【问题标题】:What the effect after interface transition?界面过渡后有什么效果?
【发布时间】:2018-09-04 20:52:24
【问题描述】:

在我的项目中有 VC 和其他 VC 作为容器。 我尝试使用viewWillTransitionToSize 方法,但是在转换后子VC(在容器中)的接口无法通过触摸使用。

我不知道那是什么影响或问题。 有人知道我的情况吗?

感谢所有回答!

【问题讨论】:

    标签: swift uiviewcontroller uicontainerview viewwilltransitiontosize


    【解决方案1】:

    我发现解决了这个问题。 如果您有同样的问题,请检查您的 viewWillTransitionToSize 覆盖函数。所有大小、视图、颜色、位置的动作都应该在过渡过程中完成。 像这样:

    斯威夫特 4.1

    ...
    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        coordinator.animate(alongsideTransition: { (_) in
            // there will be your handler for UI elements.
        }, completion: { (_) in 
    
        })
    }
    ...
    

    在我的项目中,我有 UIPageVC,它存在页面 (VC)。除了在转换时刻可见的页面(VC)之外,我处理每个页面的 PageVC func 中的转换。一切正常。 这是我的代码示例:

    MainPageViewController 类:

    ...
    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        coordinator.animate(alongsideTransition: { (_) in
            // handlers for my PageVC
    
            for vc in self.orderedViewControllers {
                if vc != self.orderedViewControllers[self.currentPageIndex{
                    vc.viewWillTransition(to: size, with: coordinator)
                }
            }
    
        }) { (_) in
            print("\nDONE: PAGEVC Rotated.")
        }
    }
    

    也许这段代码将来会对任何人有所帮助。

    【讨论】:

      猜你喜欢
      • 2021-07-02
      • 2017-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多