2012-04-24 68 views
0

我一直在寻找一段时间,但我想要的基本上是“presentModalViewController”动画,但另一种方式......我想让屏幕的顶部落到底部以揭示这一页。有人知道那是什么吗?iPhone子视图动画:滑下来

这是我到目前为止的代码,但它发生得太快了......我如何减慢速度?

-(void)gotToCreateGameViewController{ 
CreateNewGameViewController *newGame = [[CreateNewGameViewController alloc]initWithNibName:@"CreateNewGameViewController" bundle:nil]; 
self.createNewGameViewController = newGame; 
createNewGameViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
[self presentModalViewController:newGame animated:YES]; 
[self.view insertSubview:newGame.view atIndex:0]; 

[newGame release]; 

回答

2

我认为你正在寻找:UIModalTransitionStyleCoverVertical

Presentation Transition Styles 
Transition styles available when presenting view controllers. 

typedef enum { 
     UIModalTransitionStyleCoverVertical = 0, 
     UIModalTransitionStyleFlipHorizontal, 
     UIModalTransitionStyleCrossDissolve, 
     UIModalTransitionStylePartialCurl, 
} UIModalTransitionStyle; 

它去底部到顶部,在解雇存在,则顶部至底部。要从上到下过渡,您需要自行推出,或从下面的目标vc开始,以模态方式呈现启动vc。

+0

我更新了我的问题,有一些代码,我都试过了。 ..它不会工作,我想要的方式 – nfoggia 2012-04-24 17:50:01

1

试试这个代码

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

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

     transition.delegate = self; 

     transition.subtype =kCATransitionFromTop; 

     transition.delegate = self; 


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

     [self.view.layer addAnimation:transition forKey:nil]; 

     [newGame release]; 

注意UIModalTransitionStyle只会工作,适用于iPad的应用。请参阅文档。

+0

我得到一些错误,containerView没有宣布(女巫它不是),但我不知道该用什么来代替containerView。 – nfoggia 2012-04-25 18:15:32

+0

@nfoggia更新的代码。现在试试 – rakeshNS 2012-04-26 03:39:52

0

我hackish的答案:

如果你移动你的初始视图下为y = 960(你可能必须添加另一种观点,然后剪切并粘贴到一切这一观点),并把你的第二个观点,在y = 0,你可以实现下面的代码。实例化一个BOOL后(我打电话给我movedUp):

-(void)moveView:(float)d{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:d]; 

    CGRect rect = self.view.frame; 
    if (!movedUp) 
    { 
     rect.origin.y -= 960; 
     rect.size.height += 960; 
    } 
    else 
    { 
     // revert back to the normal state. 
     rect.origin.y += 960; 
     rect.size.height -= 960; 
    } 
    self.view.frame = rect; 

    [UIView commitAnimations]; 
    movedUp = !movedUp; 
} 
- (void)viewDidAppear:(BOOL)animated 
{ 
    [self moveView:0.0]; 
    [super viewDidAppear:animated]; 
} 

然后我连接两个按钮(一个在每个视图)以下:

-(IBAction)setViewMovedUp:(id)sender 
{ 
    [self moveView:0.5]; 
}