2012-04-26 91 views
0

这是我迄今为止。我想要做的是通过在新视图下滑动屏幕,使起始视图(startUpView)切换到另一个视图(creatNewGameViewController)。它现在所做的一切是正常切换视图,但我真的想要这种滑动效果。如果任何人都可以发现我的代码中的错误,将不胜感激。由于UIView动画交换视图(滑下)

#import "CreateNewGameViewController.h" 
@synthesize createNewGameViewController; 
UIButton *mainCreateGame = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[mainCreateGame addTarget:self 
        action:@selector(goToCreateGameViewController) 
     forControlEvents:UIControlEventTouchUpInside]; 
[mainScroll addSubview:mainCreateGame]; 
mainCreateGame.frame = CGRectMake(65, 10, 190, 60); 

-(void)goToCreateGameViewController{ 
CreateNewGameViewController *newGame = [[CreateNewGameViewController alloc]initWithNibName:@"CreateNewGameViewController" bundle:nil]; 
self.createNewGameViewController = newGame; 

CATransition *transition = [CATransition animation]; 
transition.duration = 2; 
transition.timingFunction = [CAMediaTimingFunction  
          functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
transition.type =kCATransitionMoveIn; 


CATransition *transition1 = [CATransition animation]; 
transition1.duration = 2; 
transition1.timingFunction = [CAMediaTimingFunction  
          functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
transition1.type =kCATransitionMoveIn; 
transition1.subtype =kCATransitionFromTop; 

transition1.delegate = self; 

[createNewGameViewController.view.layer addAnimation:transition1 forKey:nil]; 
transition1.subtype =kCATransitionFromTop; 

transition1.delegate = self; 



[self presentModalViewController:newGame animated:NO]; 
[self.view insertSubview:newGame.view atIndex:0]; 

[createNewGameViewController.view.layer addAnimation:transition1 forKey:nil]; 

[newGame release]; 
+0

presentModalViewController:animated:可能将新视图置于旧视图之上?此外,呈现视图,然后插入其视图似乎有点'hackish' – 2012-04-26 03:54:58

回答

0

的UIView有一个叫做从视图转变来查看动画类方法,检查是否有帮助,告诉我是怎么回事:)建议

UiView

一块,你真的应该使用导航控制器,故事板或类似的东西来做那种视图转换,因为这是正确的方法。

+0

你是什么意思?即时通讯新的这个东西,所以我不知道什么(或为什么)我应该使用这个东西的一半大声笑 – nfoggia 2012-04-26 04:58:32

+0

ios sdk面向MVC,它有控制器用于在屏幕之间切换 – 2012-04-26 10:53:33