2012-08-25 42 views
2

我正在開發一個iPhone應用程序,我需要在動畫中緩慢向上移動第一個視圖控制器並移至第二個視圖控制器。我正在考慮使用CoreAnimation將第一個視圖控制器緩慢向上移動並推送到下一個視圖控制器。有人可以幫助提供什麼類/ apis可用於實現這一目標嗎?iPhone:動畫向上移動視圖控制器

謝謝!

回答

0

試試這個,

[UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:yourfirstview cache:YES]; 
    [UIView setAnimationDidStopSelector:@selector(remove_view)]; 
    //change frame here 
    yourfirstview.frame =CGRectMake(0,-480,320,480); 
    [UIView commitAnimations]; 

    -(void)remove_view 
    { 
     [yourfirstview removeFromSuperview]; 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:1.0]; 
     [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:yoursecondview cache:YES]; 
     //change frame here 
     yoursecondview.frame =CGRectMake(0,0,320,480); 
     [UIView commitAnimations]; 
    } 
+1

嗨,我想推到新的視圖控制器,而不是UIView。所以,我想使用核心動畫(它有CATransition支持向上移動)並提交動畫並使用pushViewController移動到下一個屏幕。 – Stella

0

您可以輕鬆地做到這一點使用多個單一視圖控制器上UIView小號

按照蘋果的文檔:

在iOS中4及更高版本,使用基於塊的動畫方法。

因此,爲了產生預期的結果,使用下面的代碼。

UIView *mySecondView = [[UIView alloc] initWithFrame:CGRectMake(0, 480, 320, 480)]; 
[mySecondView setBackgroundColor:[UIColor redColor]]; 
[self.view addSubview:mySecondView]; 

[UIView animateWithDuration:2.0 delay:3.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 
    [mySecondView setTransform:CGAffineTransformMakeTranslation(0, -480)]; 
}completion:^(BOOL done){ 

}]; 
+0

嗨,我想推到新的視圖控制器,而不是UIView。 – Stella

+0

@ user213199推動視圖控制器是指將視圖向左移動以顯示右側的新視圖。這是使用'UINavigationController'完成的 –