2

I am reading the gyro and changing the string of a SCNText geometry to the gyro's yaw value. The change occurs inside the gyro handler that is called every 1/30 seconds. The SCNText geometry was created with Interface Builder.

I am using this code to retrieve a reference to the text:

SCNNode *textNode = [scene.rootNode childNodeWithName:@"yawText" recursively:YES];
self.text = [textNode geometry]; 
//self.txt is declared as @property (strong, nonatomic) SCNText *text;

Later on the gyro handle I do this:

CGFloat yaw = convertToDegrees(attitude.yaw);
[weakSelfText setString:[NSString stringWithFormat:@"%.1f", yaw]];
NSLog(@"yaw = %1f", yaw);

// I had to declare weakSelfText outside the gyro handler
// because Xcode was complaining
// weakSelfText is declared like this
// __weak typeof(self.text) weakSelfText = self.text;

NSLog prints the values correctly but there is no change on the SCNText.

Yes, I have tried to change the text on the main thread. No change.

4

1 回答 1

5

在您的 SCNText 几何体上设置string就足够了。

textNode.geometry.string = "0.5"

如果您没有看到任何变化,那么 weakSelfText 并没有指向您认为的位置。确保您没有在某处删除参考:

NSAssert(weakSelfText == textNode.geometry, @"pointers not the same")
于 2016-03-02T04:21:34.130 回答