16

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

4

2 に答える 2

65

この-[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];
于 2010-09-22T06:39:34.327 に答える
1

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

self.bringSubviewToFront(self.grandchildview.superview!)
self.grandchildview.superview!.bringSubviewToFront(self.grandchildview)
于 2016-02-16T08:54:40.040 に答える