web-dev-qa-db-ja.com

bringSubviewToFrontの問題?

こんにちは、Parentview-> Multiplechildviewsがあります。 parentviewで[selfbringSubviewToFront:childview]を使用すると正常に動作しますが、childviewにgrandchildviewを追加した後、parentviewで[self bringSubviewToFront:grandchildview]を使用すると動作しませんでした。

15
senthilMuthu

-[UIView bringSubviewToFront:]メソッドは直接の子供に対してのみ機能し、孫に対しては機能しません。ビュー階層はツリーであり、通常、ビューはその「親」(またはスーパービュー)とその直接の「子」(またはサブビュー)についてのみ知っていることに注意してください。次のようなことをする必要があります。

// First, get the view embedding the grandchildview to front.
[self bringSubviewToFront:[grandchildview superview]];
// Now, inside that container view, get the "grandchildview" to front. 
[[grandchildview superview] bringSubviewToFront:grandchildview];
61
DarkDust

チェックされたソリューションからのSwiftバージョン)での私の貢献

self.bringSubviewToFront(self.grandchildview.superview!)
self.grandchildview.superview!.bringSubviewToFront(self.grandchildview)
1
Kevin ABRIOUX