incanus / SceneKitDemo

This is a little iOS 8 demo app I made for a talk at dispatch_sync in Portland in June, 2014.
17 stars 2 forks source link

property 'textSize' for SCNText ? #1

Open zhxf2012 opened 7 years ago

zhxf2012 commented 7 years ago

SceneKitDemo-master/SCNText/ViewController.m:158:56: error: property 'textSize' not found on object of type 'SCNText ' self.textNode.position = SCNVector3Make(-sceneText.textSize.width / 2 textScale, -sceneText.textSize.height / 2 * textScale, 0);

dmitriyl commented 7 years ago

Try to get the required property of sceneText following way

SCNVector3 min = SCNVector3Zero;
SCNVector3 max = SCNVector3Zero;
[sceneText getBoundingBoxMin:&min max:&max];
CGFloat textHeight = max.y - min.y;
CGFloat textWidth = max.x - min.x;

self.textNode.position = SCNVector3Make(-textWidth / 2 * textScale, -textHeight / 2 * textScale, 0);
BlackMirrorz commented 6 years ago

The textSize property is only available on macOS 10.8+. By this, I mean that if you are building a MacOS app then the variable will be accessible, whereas if you are building for IOS it is not.

If you want to get the size of your SCNText you can use it's boundingBox property to get its width and height etc.