2013-10-08 91 views
2

我在兩個故事板控制器之間的過渡動​​畫有問題。 我有一個單視圖項目與故事板中的兩個視圖控制器。Xcode自定義segue動畫

現在我的魔杖製作一個自定義的過渡動畫:

  • 我當前視圖控制器應該消失向左
  • 新的視圖控制器應該來自右

我已經一個UIStoryboardSegue類。

但是我應該寫在-(void)perform{}方法?

非常感謝,

喬納斯。

+0

只寫「定製賽格瑞」在谷歌,你會發現很多的例子。首先做一些嘗試,然後用你試過的東西來到這裏。一個例子:http://blog.jimjh.com/a-short-tutorial-on-custom-storyboard-segues.html – CRDave

+0

順便說一句,你想要什麼動畫是默認推動賽格動畫,你不必爲此編寫代碼。 – CRDave

+1

@ CRDave--僅當您想要使用UINavigationController時。如果你不想使用該控制器,那麼你必須自定義相同的轉換代碼。似乎很愚蠢的是,xcode很難打破mvc(也就是說,如果你有一個特定的控制器,你只能得到一個特定的轉換),但它就是這樣。 – mmr

回答

11

對於簡單的賽格瑞你可以嘗試這樣的事:

- (void)perform { 
    UIViewController* source = (UIViewController *)self.sourceViewController; 
    UIViewController* destination = (UIViewController *)self.destinationViewController; 

    CGRect sourceFrame = source.view.frame; 
    sourceFrame.origin.x = -sourceFrame.size.width; 

    CGRect destFrame = destination.view.frame; 
    destFrame.origin.x = destination.view.frame.size.width; 
    destination.view.frame = destFrame; 

    destFrame.origin.x = 0; 

    [source.view.superview addSubview:destination.view]; 

    [UIView animateWithDuration:1.0 
        animations:^{ 
         source.view.frame = sourceFrame; 
         destination.view.frame = destFrame; 
        } 
        completion:^(BOOL finished) { 
         UIWindow *window = source.view.window; 
         [window setRootViewController:destination]; 
        }]; 
} 
+0

非常感謝你! –