【问题标题】:UIView animated swap views (slide down)UIView 动画交换视图(向下滑动)
【发布时间】:2012-05-06 19:18:34
【问题描述】:

这是我目前所拥有的。我要做的是通过使用新视图向下滑动屏幕来使起始视图 (startUpView) 切换到另一个视图 (creatNewGameViewController)。它现在所做的只是正常切换视图,但我真的想要那种滑动效果。如果有人能在我的代码中发现错误,将不胜感激。谢谢

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

【问题讨论】:

  • 是否 presentModalViewController: 动画:可能将新视图放在旧视图之上?此外,呈现视图然后插入其视图似乎有点“骇人听闻”

标签: iphone animation view transition


【解决方案1】:

UIView 有一个类方法,称为从视图到动画视图的转换,检查是否有帮助并告诉我它是如何实现的 :)

UiView

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

【讨论】:

  • 什么意思?我对这些东西很陌生,所以我不太确定我应该用什么(或为什么)来做一半的东西哈哈
  • ios sdk 是面向 MVC 的,它有用于在屏幕之间切换的控制器
猜你喜欢
  • 1970-01-01
  • 2012-12-20
  • 2021-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多