我正在使用導航控制器的應用程序。我有一個特定的視圖控制器,在導航欄中有一個左右按鈕,每個按鈕都延伸到不同的視圖控制器。當我按下右鍵時,我只需撥打self.performSegue(withIdentifier: "ToDestination", sender: nil)
,當我回電時,我撥打_ = self.navigationController?.popViewController(animated: true)
。自定義segue過渡動畫
我的問題是當我按下左按鈕。我可以推動和彈出,但我希望過渡與右側按鈕相反。由於我按了左鍵,我想讓segue從左到右轉換,當我彈出時,我希望segue從右向左轉換。
我能得到的轉換通過做工作,我想要的方式:
//push
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "SearchController") as! SearchController
let transition: CATransition = CATransition()
let timeFunc : CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.duration = 0.5
transition.timingFunction = timeFunc
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromLeft
self.navigationController!.view.layer.add(transition, forKey: kCATransition)
self.navigationController!.pushViewController(vc, animated: true)
//pop
let transition: CATransition = CATransition()
let timeFunc : CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.duration = 0.5
transition.timingFunction = timeFunc
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
self.navigationController!.view.layer.add(transition, forKey: kCATransition)
_ = self.navigationController?.popViewController(animated: true)
這工作,但視圖控制器之間轉換時黑色閃光。有沒有更好的方式來獲得默認的過渡動畫?