简体   繁体   中英

How can I add a view from subviews on top of its superview?

I have a mainViewController and inside its nib file I added an info button, in which action is to flip between two subviews, subview A and subview B.

From mainViewController, under viewDidLoad, I'm inserting subview A. Here I notice that the info button is in front of the subview A, which is fine.

The problem comes that when pressing any buttons that are located within subview A's nib file, in which they add new subviews, the info button remains on front.

So, how can I add these later subviews on front of all parent view stacks, so the info button does not appear? or how can I hide the info button?

You can put subview infront of everything else by calling

[view bringSubviewToFront:subview];

You can hide the button (or any other UI element) by calling it's setHidden function like so:

[button setHidden:YES];

always application can only contain a one window at a time. so this is the best way.

UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
[mainWindow addSubview:yourView]; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM