簡體   English   中英

使用UIView Transition幻燈片動畫?

[英]Slide animation with UIView Transition?

我正在設置一個新的導航根。 我想在設置導航時顯示動畫。 我可以使用以下代碼設置翻轉和卷曲動畫。

UIView.transition(with: self.window!, duration: 2, options: .transitionFlipFromLeft, animations: {
    let navController = UINavigationController()
    // App Theming
    navController.navigationBar.barTintColor = .white
    navController.navigationBar.tintColor = .white
    navController.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    navController.pushViewController(viewContoller, animated: true)
    self.window?.rootViewController = navController
    self.window?.makeKeyAndVisible()
}, completion: {_ in})

但是,我需要為此從左到右設置幻燈片動畫。 任何人都可以讓我知道如何實現這一目標嗎?

如果要偽造對新根視圖的推送,可以執行以下操作。

    let navController = UINavigationController()
    //App Theming
    navController.navigationBar.barTintColor = .white
    navController.navigationBar.tintColor = .white
    navController.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    //create our fake animation
    let trans = CATransition()
    trans.type = kCATransitionPush
    trans.subtype = kCATransitionFromRight
    trans.duration = 0.4
    self.window?.layer.add(trans, forKey: nil)
    //set your window change here
    self.window?.rootViewController = navController
    self.window?.makeKeyAndVisible()

完全未經測試,但我可以肯定的是我過去曾經做過。 如果這樣不起作用,請嘗試設置rootViewController,然后添加動畫。

暫無
暫無

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

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