0

我想在不使用 removeFromSuperView 和 addSubview 的情况下动态更改 UIView 的内容。代码是我想要做的图像。

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];
4

2 回答 2

1

确实。如果您希望它看起来不错,请使用您想要的属性创建“结束”视图并使用静态转换方法:+transitionFromView:toView:duration:options:completion:.

这将根据需要删除和添加视图,因此您不必调用这些方法。否则,您可以使用janusfidel-setHidden:建议的方法,以隐藏您不想看到的视图。

于 2012-10-31T09:34:47.463 回答
0
//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;
}
}
于 2012-10-31T09:56:27.907 回答