ios - ConvertPointFromView 返回 NAN
<p><p>我正在尝试用一些 SKSpriteNode 对象填充我的场景。但是,在其他 View 中,我已经将这些对象用作 UIImageView 的。所以我有正常的坐标,我正在尝试转换为 GL 坐标。 </p>
<p>我是这样做的:</p>
<pre><code>SKSpriteNode *title = ;
CGPoint titlePoint = CGPointMake(238.0, 50.0); //coordinates already known.
NSLog(@"X1: %f, Y1: %f", titlePoint.x, titlePoint.y);
CGPoint titlePosition = ;
NSLog(@"X: %f, Y: %f", titlePosition.x, titlePosition.y);
title.position = titlePosition;
NSLog(@"X: %f, Y: %f", titlePosition.x, titlePosition.y);
</code></pre>
<p>然后,第一个 NSLog 没问题,但是,接下来的两个 NSLog 正在为 x 和 y 值打印 <strong>NAN</strong>。</p>
<p>有人知道这里发生了什么吗? </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我猜 <code>self</code> 是一个 <code>SKScene</code>。我怀疑 <code>self.view == nil</code>(意味着当前没有 <code>SKView</code> 呈现 <code>self</code>)。 <a href="https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKScene_Ref/Reference/Reference.html#//apple_ref/doc/uid/TP40013024-CH1-SW17" rel="noreferrer noopener nofollow">documentation of <code>convertPointFromView:</code></a>说:</p>
<blockquote>
<p>The scene must be presented in a view before calling this method.</p>
</blockquote></p>
<p style="font-size: 20px;">关于ios - ConvertPointFromView 返回 NAN,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25729352/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25729352/
</a>
</p>
页:
[1]