Reputation: 1563
I Want to change contents of UIView dynamically without using removeFromSuperView and addSubview.the codes is an image of what I want to do.
int screenWidth = [[UIScreen mainScreen] bounds].size.width;
int screenHeight = [[UIScreen mainScreen]bounds].size.height;
UIView *currentView = [[UIView alloc]initWithFrame:CGRectMake(0,0,screenWidth,screenHeight)];
UIView *nextView = [[UIView alloc]initWithFrame:CGRectMake(0,0,screenWidth,screenHeight)];
[self.view addSubview:currentView];
currentView = nextView;
//when this code run,appearing currentView swap nextView.
[self.view reload];
Upvotes: 0
Views: 699
Reputation: 4901
//in viewdidload
{
........
........
[self.view addSubview:currentView];
[self.view addSubview:nextView];
nextView .hidden = YES;
}
-(void)changeView
{
if(!currentView .hidden)
{
currentView .hidden =YES;
nextView .hidden = NO;
}
else
{
currentView .hidden =NO;
nextView .hidden = YES;
}
}
Upvotes: 0
Reputation: 96984
Definitely. If you want it to look nice, create the "end" view with the attributes you want and use a static transition method: +transitionFromView:toView:duration:options:completion:
.
This will remove and add views, as needed, so that you don't have to call those methods. Otherwise, you can use the -setHidden:
method suggested by janusfidel, in order to hide the view you don't want to see.
Upvotes: 1