参考
Swift3 - PresentsViewControllerで左右に画面遷移する方法
push遷移で左に行きたい
Swiftで画面遷移をしたい時 、私は pushViewController
を頻繁に使うのですがpushViewController
で画面遷移させようとするとデフォルト状態だと必ず右遷移
になってしまいます
どうしても、どうしても、左に遷移させたかった。。。 でも popViewControllerAnimated
を使うと、結局それは前の画面に戻るだけで、行きたい画面に行けないのです。
私が行きたかった画面は、二つ前の画面で、一回のタップ処理で、二つ前の画面に左遷移
させたいのです。下記のqiitaを読んでみればpresent modally 2個前の画面に戻る
というのがあるのですが、
私はあくまでも pushViewController
で左遷移したいんだよお、ということで色々考えなんとか下記のような記述でpushViewController
による 左遷移
を実現させることができたのですメモしておきます
HowToLeftPushViewController.swift
@IBAction func backButtn(sender: AnyObject) {
//IBActionでボタンを定義
let transition = CATransition()
//CATransitionというメソッドを使う
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
//なんか色々書いてあるけどよくわからない
transition.type = kCATransitionPush
//push遷移するよという定義
transition.subtype = kCATransitionFromLeft
//kCATransitionFromLeftのLeftをRightにすれば右遷移に変わる
self.navigationController!.view.layer.addAnimation(transition, forKey: nil)
let storyboard = UIStoryboard(name: "AuthSupporterCode", bundle: nil)
//ストーリーボードのインスタンス化
let HowToLeftPush = storyboard.instantiateViewControllerWithIdentifier("AuthSupporterCode") as! AuthSupporterCodeViewController
//遷移先のViewControllerインスタンス化
self.navigationController?.pushViewController(HowToLeftPush, animated: true )
//push遷移実行処理
}