OGeek|极客世界-中国程序员成长平台

标题: ios - ConvertPointFromView 返回 NAN [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 01:42
标题: ios - ConvertPointFromView 返回 NAN

我正在尝试用一些 SKSpriteNode 对象填充我的场景。但是,在其他 View 中,我已经将这些对象用作 UIImageView 的。所以我有正常的坐标,我正在尝试转换为 GL 坐标。

我是这样做的:

SKSpriteNode *title = [SKSpriteNode spriteNodeWithImageNamed"labirinto_title"];
    CGPoint titlePoint = CGPointMake(238.0, 50.0); //coordinates already known.
    NSLog(@"X1: %f, Y1: %f", titlePoint.x, titlePoint.y);
    CGPoint titlePosition = [self convertPointFromView:titlePoint];
    NSLog(@"X: %f, Y: %f", titlePosition.x, titlePosition.y);
    title.position = titlePosition;
    NSLog(@"X: %f, Y: %f", titlePosition.x, titlePosition.y);

然后,第一个 NSLog 没问题,但是,接下来的两个 NSLog 正在为 x 和 y 值打印 NAN

有人知道这里发生了什么吗?



Best Answer-推荐答案


我猜 self 是一个 SKScene。我怀疑 self.view == nil(意味着当前没有 SKView 呈现 self)。 documentation of convertPointFromView:说:

The scene must be presented in a view before calling this method.

关于ios - ConvertPointFromView 返回 NAN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25729352/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4