About bringSubviewToFront

I bring the front control with the code below:

[self.view bringSubviewToFront:control]; 

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

+4
source share
2 answers

You would check the presentation order in the supervision (of the controls, in your case self.view) subviews .

The view at index 0 in the subview is the view at the very end, and then the view at index 1 will be on top, and the view at index 2 will be on top of the view at index, etc.
(basically a view is on top of views with a lower index compared to its 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 } 
+4
source

If these controls have the same parent view, their z-order is determined by their index in the subviews array:

subviews : the order of the subviews in the array reflects their visible order on the screen, with a view at index 0 being the largest view.

So your steps will be:
1. Get control
2. Get their indices in the parent subviews array (using the indexOfObject: method)
3. Management with a large index in front

+2
source

Source: https://habr.com/ru/post/1341517/


All Articles