2014-02-10 100 views
2

是否可以更改ViewContoller Pop動畫的方向。
現在,當我們推VC時,它顯示的動畫從左到右滑動,從右到左彈出。
但我想動畫幻燈片從流行VC左到右。如何更改PopViewController上ViewController的動畫方向

我試過使用UIViewAnimationTransition

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:0.75]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
[UIView commitAnimations]; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDelay:0.375]; 
[self.navigationController popViewControllerAnimated:NO]; 
[UIView commitAnimations]; 

但它沒有我需要的動畫是從左向右滑動。這是我得到的動畫

typedef enum { 
    UIViewAnimationTransitionNone, 
    UIViewAnimationTransitionFlipFromLeft, 
    UIViewAnimationTransitionFlipFromRight, 
    UIViewAnimationTransitionCurlUp, 
    UIViewAnimationTransitionCurlDown, 
} UIViewAnimationTransition; 
+0

嘗試: - 第一場演出的動畫和動畫的完成彈出的viewController。 – Leena

+0

您是否找到解決方案? – Crashalot

+0

@Crashalot,我添加了我已使用的代碼的答案,請檢查。 – Dilip

回答

4

我用下面的代碼..

添加這didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Override point for customization after application launch. 
    //This line of code needed so you will not see the back window when its pop, match it with your app design. 
    self.window.backgroundColor = [UIColor whiteColor]; 
    return YES; 
} 

如果您POP代碼添加以下代碼,

CATransition* transition = [CATransition animation]; 
transition.duration = 0.4f; 
transition.type = kCATransitionPush; 
transition.subtype = kCATransitionFromRight; 
[self.navigationController.view.layer addAnimation:transition 
              forKey:kCATransition]; 
[self.navigationController popViewControllerAnimated:NO]; 

查看此GIF中的結果,
http://www.giphy.com/gifs/l2YSeBELE1phMEd5S

0

您可以使用[UIView beginAnimations:]您的情況。 setTransitionStyle如你所需。檢查avalable UIViewAnimationTransitionStyle蘋果文檔中參考這個https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html

+0

Thanx for reply。其實我已經嘗試過,但它沒有我需要的動畫,從左到右滑動。 – Dilip

+0

我已經使用這個http://stackoverflow.com/questions/2942221/how-to-change-pop-view-controller-animation-on-back-button代碼,這是很好,但doent包含我需要的動畫。 – Dilip

-1
[UIView animateWithDuration:0.5f animations:^{ 
     self.myButton.transform = CGAffineTransformMakeScale(3, 3); 
    } completion:^(BOOL finished){}]; 
    // for zoom out 
    [UIView animateWithDuration:0.5f animations:^{ 

     self.myButton.transform = CGAffineTransformMakeScale(1, 1); 
    }completion:^(BOOL finished){}]; 
    //View ANimation 
    [UIView transitionWithView: self.navigationController.view 
         duration: 0.5 
         options: UIViewAnimationOptionTransitionCurlDown 
        animations: ^{ 

         [self.navigationController popToRootViewControllerAnimated:YES]; 
        } 
        completion: nil ]; 
1

乾杯,這裏是swift 3.0〜4.0版本。

let transition = CATransition() 
transition.duration = 0.4 
transition.type = kCATransitionPush 
transition.subtype = kCATransitionFromRight 
self.navigationController?.view.layer.add(transition, forKey: kCATransition) 
self.navigationController?.popViewController(animated: false) 
+0

工作很好,謝謝! – agrippa

0
let story = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController 

    UIView.beginAnimations("", context: nil) 
    UIView.setAnimationDuration(1.0) 
    UIView.setAnimationCurve(UIViewAnimationCurve.easeInOut) 
    UIView.setAnimationTransition(UIViewAnimationTransition.flipFromRight, for: (self.navigationController?.view)!, cache: false) 
    self.navigationController?.pushViewController(story, animated: true) 
    UIView.commitAnimations() 
0

你可以使用塊完成後的動畫做的工作:

UIView.animate(withDuration: 0.75, animations: {() -> Void in 

    UIView.setAnimationCurve(UIViewAnimationCurve.easeInOut) 
    self.navigationController?.popViewController(animated: true) 

})