簡體   English   中英

過渡動畫不起作用Swift 5

[英]Transition Animation is not working Swift 5

我正在嘗試使用點擊手勢導航從一個視圖控制器導航到另一個視圖控制器。 我想在其中添加過渡動畫。 我嘗試了兩種方法,但對我沒有用。 -

第一種方法:

               UIView.animate(withDuration: 0.5) { ()-> Void in

                            let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                            let myTabBarController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as! ProfileViewController
                            var appDel = UIApplication.shared.delegate as! AppDelegate
                            appDel.window?.rootViewController = myTabBarController

                        self.view.layoutIfNeeded()
                }

第二種方法:

UIView.animate(withDuration: 0.25,
               delay: 0.0,
               options: [.curveEaseIn],
               animations: {


    let controller = self.storyboard!.instantiateViewController(withIdentifier: "mainMenuViewController") as! MainMenuViewController

    self.addChild(controller)
    self.view.addSubview(controller.view)
    controller.didMove(toParent: self)

}, completion: nil)

有人可以告訴我解決方案嗎?

試試這個禮物

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as! ProfileViewController
self.present(nextViewController, animated:true, completion:nil)

如果您提供一個ViewController那么您只能將其關閉,這可以通過以下代碼完成

self.dismiss(animated: true, completion: nil)

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "profileViewController") as! ProfileViewController
self.navigationController?.pushViewController(nextViewController, animated:true)

如果按下ViewController則只能彈出它,可以通過以下代碼完成

self.navigationController?.popViewController(animated: true)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM