简体   繁体   中英

ios how to hide one uiview and push another uiview at the same position

I want to set myview hidden and view visible, how can I do this. This is the code I got so far but it makes everything hidden.

CGRect frame = CGRectMake(185, 960, 768, 1004); 
HiUIView *view = [[UIView alloc] initWithFrame:frame];
view.backgroundColor = [UIColor redColor];

[self.myview addSubview:view];
[self.myview setHidden:YES];

You are adding a view inside another and then hide the second. The first is child of the second, so is hidden too.

You can try adding "view" in the parent of "myview".

why not put both views in a container? let the current vc's view be the container of your views.

Maybe you can do something like this:

UIView *view = [[UIView alloc]initWithFrame:self.myview.frame];
[self.view addSubView:self.myview];
[self.view addSubView:view];
self.myview.hidden = YES;

Try instead in your sample:

[self.myview setHidden:YES]; 

make

[self.myview setBackgroundColor: [UIColor clearColor]]; 

The problem in your code is that you are adding a view to myView and then hiding the parent view ie myview in your case ,Use this

UIView *_viewTmp = [[UIView alloc]initWithFrame:myview.frame];
[myview.superview addSubview:_viewTmp];
myview.hidden = YES;

I hope this will help.

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