2012-04-24 69 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]; 
}