About bringSubviewToFront
Solution 1
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
}
Solution 2
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
SajjadZare
Updated on August 21, 2022Comments
-
SajjadZare over 1 year
I bring a control to front with the below code:
[self.view bringSubviewToFront:control];
How can I recognize between two controls; which one is in front and which one is in back