2012-10-31 23 views
0

我想動態改變UIView的內容,而不使用removeFromSuperView和addSubview.the代碼是我想要做的事情的圖像。我可以動態更改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]; 

回答

1

當然。如果您希望它看起來不錯,請使用所需屬性創建「結束」視圖,並使用靜態transition方法:+transitionFromView:toView:duration:options:completion:

這將根據需要刪除和添加視圖,以便您不必調用這些方法。否則,您可以使用建議的-setHidden:方法janusfidel,以隱藏您不想看到的視圖。

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; 
} 
} 
相關問題