画面遷移を分けたい
BActionを押したら別のクラスに定義した画面遷移のための関数を呼び出して画面遷移をしたいと思うのですができません。下記のようなコードを実行すると下記画面のようなエラーが発生します。原因とアドバイスをいただかれば幸いです。
呼び出し元
CustomScreenTransitionViewControllerクラスにhome(viewController)に遷移するためのコードが記述してあります
@IBAction func HomeBiewButton(_ sender: Any) { CustomScreenTransitionViewController().home() }
呼び出される側
import UIKit class CustomScreenTransitionViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func home() { let transition = CATransition() //CATransitionというメソッドを使う transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) //なんか色々書いてあるけどよくわからない transition.type = kCATransitionPush //push遷移するよという定義 transition.subtype = kCATransitionFromLeft //kCATransitionFromLeftのLeftをRightにすれば右遷移に変わる self.navigationController!.view.layer.add(transition, forKey: nil) let storyboard = UIStoryboard(name: "Main", bundle: nil) //ストーリーボードのインスタンス化 let HowToLeftPush = storyboard.instantiateViewController(withIdentifier: "HomeView") as! ViewController //遷移先のViewControllerインスタンス化 self.navigationController?.pushViewController(HowToLeftPush, animated: true ) //push遷移実行処理 TopMenu.isHidden = true } }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。