动态切换视图

动态切换视图

 

 

准备:

2个视图,视图A和视图B,视图A种有一个按钮,点击后显示视图B,视图B中有1个按钮,点击后返回视图A.

 

视图A->视图B(视图B是视图A的子视图):

在视图A中的代码:

	secondView=[[View02 alloc] initWithNibName:@"View02" bundle:nil];
	
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:1];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	[UIView  setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 
							forView:self.view 
							  cache:YES];
	
	[self.view addSubview:secondView.view];
	
	[UIView commitAnimations];
 其中  secondView相当于视图B,注意 [UIView  setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 

forView:self.view 

  cache:YES];

其中用的是forView:self.view

 

 

视图B返回视图A:

视图B中的代码:

	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:1];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	[UIView  setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 
							forView:self.view.superview 
							  cache:YES];
	
	[self.view removeFromSuperview];
	
	[UIView commitAnimations];
 

其中用的是forView:self.view.superview

 

 

 

 

 

 

 

你可能感兴趣的:(视图)