2016-08-05 80 views
6

我正在使用這行代碼來關閉我的視圖控制器self.dismiss(animated: true, completion: nil),但我不喜歡當前的動畫。相反,我想從左到右滑動。以下是我試圖測試一個動畫,但不起作用。關閉視圖控制器與自定義動畫?

UIView.animate(withDuration: 1.0, delay: 0.0, options: UIViewAnimationOptions.curveEaseIn, animations: { 

     let transition = CATransition() 
     transition.duration = 10 
     transition.type = kCATransitionPush 
     transition.subtype = kCATransitionFromLeft 

     self.view.layer.add(transition, forKey: kCATransition) 

     self.dismiss(animated: false, completion: nil) 
     }, completion: nil) 
+0

我相信這裏發生的一切就是視圖控制器在該動畫開始同時被解僱。你可以嘗試移動self.dismiss(...)到動畫完成塊,看看是否有效。如果沒有,你可以在網上找到很多關於如何定製賽車的教程。我從來沒有這樣做過,所以我不能給你任何指點,但雷文德里克總是一個深入教程的好地方。 https://www.raywenderlich.com/86521/how-to-make-a-view-controller-transition-animation-like-in-the-ping-app – Erik

回答

20
let transition: CATransition = CATransition() 
transition.duration = 0.5 
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 
transition.type = kCATransitionReveal 
transition.subtype = kCATransitionFromRight 
self.view.window!.layer.add(transition, forKey: nil) 
self.dismissViewControllerAnimated(false, completion: nil) 
相關問題