LoginSignup
3
5

More than 3 years have passed since last update.

遷移先でdismissした後に画面更新したい場合

Posted at

iOS13からModalで画面遷移をする際にフルスクリーンではなくシート型に変更になりました。この場合、UIとしては格好いい(スワイプで閉じられる)のですが、遷移元の画面更新をviewWillAppearでやっていた場合、iOS13では呼ばれなくなりました。

対応策

遷移先のViewControllerのなかで下記のメソッドを呼んでやる必要があります。iOS12で呼ぶと二重で実行されてしまうので、実行をiOS13以上にしてやる必要があります。

override func viewWillAppear(_ animated: Bool) {

    if #available(iOS 13.0, *) {
        presentingViewController?.beginAppearanceTransition(false, animated: animated)
    }

    super.viewWillAppear(animated)

}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    if #available(iOS 13.0, *) {

        presentingViewController?.beginAppearanceTransition(true, animated: animated)
        presentingViewController?.endAppearanceTransition()
    }
}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    if #available(iOS 13.0, *) {
        presentingViewController?.endAppearanceTransition()
    }
}
3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5