1

in my program there is a MainView and during the program user can add some subView. for handling them i want to know which subView now are showing on top level.

NOTE: I do not remove subViews unless the user wants. and the subviews are in different sizes and may have overlap or not.

2 Answers 2

1

subviews

The receiver’s immediate subviews. (read-only)

@property(nonatomic, readonly, copy) NSArray *subviews

You can use this property to retrieve the subviews associated with your custom view hierarchies. 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.

From UIView Class Reference

Sign up to request clarification or add additional context in comments.

Comments

0

UIView declares a property which contains its subviews:

@property(nonatomic, readonly, copy) NSArray *subviews

As you add subviews, they are added to that array. The subview with the highest index shows up on top.

There are many methods in UIView that can be used to manipulate the subviews without having to play around with the array directly:

– addSubview: – bringSubviewToFront: – sendSubviewToBack: – removeFromSuperview – insertSubview:atIndex: – insertSubview:aboveSubview: – insertSubview:belowSubview: – exchangeSubviewAtIndex:withSubviewAtIndex: – isDescendantOfView: 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.