2016-04-24 5 views
1

SCNTextの境界ボックスを確認しようとしていますが、getBoundingBoxMin:max:は常にゼロになります。SCNText getBoundingBoxMin:最大:常にゼロ

これはSCNTextクラス拡張内で実行されるコードなので、self[textNode geometry]です。私もこの

[self setString:newText]; 
    SCNVector3 min = SCNVector3Zero; 
    SCNVector3 max = SCNVector3Zero; 

    [self getBoundingBoxMin:&min max:&max]; 

    CGSize sizeMax = CGSizeMake(max.x - min.x, 
           max.y - min.y); 

sizeMaxを試してみました

[self setString:newText]; 
    SCNVector3 min = SCNVector3Zero; 
    SCNVector3 max = SCNVector3Zero; 

    SCNNode *textNode = [SCNNode nodeWithGeometry:self]; 
    [textNode getBoundingBoxMin:&min max:&max]; 

    CGSize sizeMax = CGSizeMake(max.x - min.x, 
           max.y - min.y); 

は常にゼロです。

注:問題が発生する理由を確認しました。

この調整は、このようなブロック内で呼び出されたときに問題が起こる:

dispatch_async(dispatch_get_main_queue(), 
       ^{     }); 

ので、私はメインスレッドからこのコードを呼び出した場合、それはに動作します:

[self setString:newText]; 
SCNVector3 min = SCNVector3Zero; 
SCNVector3 max = SCNVector3Zero; 

SCNNode *textNode = [SCNNode nodeWithGeometry:self]; 
[textNode getBoundingBoxMin:&min max:&max]; 

CGSize sizeMax = CGSizeMake(max.x - min.x, 
          max.y - min.y); 

が、私はこれを別のスレッドから呼び出すとは動作しません。

dispatch_async(dispatch_get_main_queue(), 
      ^{     
[self setString:newText]; 
SCNVector3 min = SCNVector3Zero; 
SCNVector3 max = SCNVector3Zero; 

SCNNode *textNode = [SCNNode nodeWithGeometry:self]; 
[textNode getBoundingBoxMin:&min max:&max]; 

CGSize sizeMax = CGSizeMake(max.x - min.x, 
          max.y - min.y); 

}); 

問題は、このブロックがディスパッチブロックから呼び出されているため、メインキューに再ディスパッチする必要がありますが、これを行うとコードが機能しなくなります。理論的には、ブロックをメインキューにディスパッチすることは、メインスレッドからブロックを実行することと同等でなければなりませんが、明らかにそうではありません。

あなたはどんな回避策を知っていますか?コメントから

+0

'SCNTransaction'に役立つことを包むのですか? (継続時間を0に設定、開始、コミット) – mnuages

答えて

0

あなたはトランザクションでそれをラップしようとすることができます:

[SCNTransaction begin]; 
[SCNTransaction setAnimationDuration:0]; 
... 
[SCNTransaction commit]; 
+0

ありがとう!!!!!!!!! – SpaceDog