`
stephen830
  • 浏览: 2968935 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

动态切换视图

 
阅读更多

动态切换视图

 

 

准备:

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

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics