質問

こんにちは、私はParentViewを持っています - >複数のChildViews。 ParentViewで[selbingsubviewtofront:ChildView]を使用する場合、それは正常に動作します。しかし、grandChildViewをChildViewに追加した後、[selbingsubviewtofront:grandChildView]を使用すると、それはうまくいきませんか?

役に立ちましたか?

解決

-[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];

他のヒント

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

self.bringSubviewToFront(self.grandchildview.superview!)
self.grandchildview.superview!.bringSubviewToFront(self.grandchildview)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top