开发者

About bringSubviewToFront

开发者 https://www.devze.com 2023-02-13 13:20 出处:网络
I bring a control to front with the below code: [self.view bringSubviewToFront:con开发者_JAVA百科trol];

I bring a control to front with the below code:

[self.view bringSubviewToFront:con开发者_JAVA百科trol];

How can I recognize between two controls; which one is in front and which one is in back


You would check the order of the view in the superview's (of the controls, in your case self.view) subviews property.

The view at the index 0 in the superview's subview is the view at the very back, and then the view at index 1 will be on top of it, and the view at index 2 will be on top of the view at index, etc
(basically a view is on top of the views with a lesser index compared to it's own index)

NSInteger indexOfControl1 = [[self.view subviews] indexOfObject:control1];
NSInteger indexOfControl2 = [[self.view subviews] indexOfObject:control2];
if (indexOfControl1 > indexOfControl2) {
    //control1 is on top of control2
}


If those controls have the same parent view their z-order is defined by their index in subviews array:

subviews: The order of the subviews in the array reflects their visible order on the screen, with the view at index 0 being the back-most view.

So your steps will be:
1. Get controls
2. Get their indexes in parent's subviews array (using indexOfObject: method)
3. Control with bigger index is in front

0

精彩评论

暂无评论...
验证码 换一张
取 消