【问题标题】:Push ViewController inside View that was presented with hero animation将 ViewController 推送到带有英雄动画的 View 中
【发布时间】:2021-01-16 16:38:48
【问题描述】:

标题几乎说明了一切。我有一个ViewController,我的present 是这样的:

let communityVC = self.storyboard?.instantiateViewController(withIdentifier: "CommunityVC") as! CommunityViewController
communityVC.hero.modalAnimationType = .zoomSlide(direction: .right)
let addButtonHeroID = "addWishButtonID"
self.addButton.heroID = addButtonHeroID
communityVC.homeButton.heroID = addButtonHeroID
self.present(communityVC, animated: true, completion: nil)

问题是comunityVC 我想push 另一个ViewController。这有可能吗?我真的找不到有效的Swift 解决方案。

【问题讨论】:

    标签: ios swift model-view-controller uiviewcontroller uinavigationcontroller


    【解决方案1】:

    你需要在嵌入UINavigationController后呈现communityVC,然后你可以将视图控制器推入communityVC,这样你就可以使用navigationController?.pushViewController(vc, animated: true)communityV推入ViewController

        let communityVC = self.storyboard?.instantiateViewController(withIdentifier: "CommunityVC") as! CommunityViewController
        let navController = UINavigationController(rootViewController: communityVC) 
        communityVC.hero.modalAnimationType = .zoomSlide(direction: .right)
        let addButtonHeroID = "addWishButtonID"
        self.addButton.heroID = addButtonHeroID
        communityVC.homeButton.heroID = addButtonHeroID
        self.present(navController, animated: true, completion: nil)
    

    【讨论】:

    • '线程 1:“应用程序试图以模态方式呈现具有父视图控制器 的视图控制器 。” '
    • 哦,我自己也看到了。。谢谢老兄!像魅力一样工作
    • 嘿 Piyush,您的解决方案运行良好。但是当简单地在另一个ViewController 中调用self.navigationController.push(someVC) 时,就像在modalView 中一样推送它。如果我想在另一个 ViewController 中使用默认推送动画,我该如何重置
    猜你喜欢
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多