【问题标题】:Changing the value of string on SCNText produces no change更改 SCNText 上的字符串值不会产生任何变化
【发布时间】:2016-06-14 12:29:39
【问题描述】:

我正在读取陀螺仪并将SCNText 几何体的字符串更改为陀螺仪的偏航值。更改发生在每 1/30 秒调用一次的陀螺处理器内部。 SCNText 几何是使用 Interface Builder 创建的。

我正在使用此代码来检索对文本的引用:

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

稍后在陀螺手柄上我这样做:

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 正确打印值,但 SCNText 没有变化。

是的,我已尝试更改主线程上的文本。没有变化。

【问题讨论】:

    标签: ios scenekit scnnode scntext


    【解决方案1】:

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

    textNode.geometry.string = "0.5"
    

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

    NSAssert(weakSelfText == textNode.geometry, @"pointers not the same")
    

    【讨论】:

    • 太棒了!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-13
    • 2021-08-21
    • 2016-02-07
    • 2013-04-28
    相关资源
    最近更新 更多