の境界ボックスを決定しようとしていますSCNText
が、 getBoundingBoxMin:max:
常にゼロになります。
SCNText
これは、クラス拡張内で実行されるコードでself
あり、[textNode geometry]
.
[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);
私もこれを試しました
[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
は常にゼロです。
注: 問題が発生する理由を発見しました。
この調整が次のようにブロック内で呼び出されると、問題が発生します。
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);
});
問題は、このブロックがディスパッチ ブロックから呼び出されることです。そのため、メイン キューに再ディスパッチする必要がありますが、そうするとコードが機能しなくなります。理論的には、ブロックをメイン キューにディスパッチすることは、メイン スレッドからブロックを実行することと同等のはずですが、明らかにそうではありません。
皆さんは何か回避策を知っていますか?