在我的项目中有VC和其他VC作为容器。
我尝试使用 viewWillTransitionToSize
方法,但转换后子 VC 的接口(interface)(位于容器中)无法通过触摸使用。
我不知道这是什么效果或问题。 有人了解我的情况吗?
感谢您的所有回答!
最佳答案
我发现可以解决这个问题。
如果您遇到同样的问题,请检查您的 viewWillTransitionToSize
覆盖函数。所有大小、 View 、颜色、位置的操作都应该沿着过渡完成。
像这样:
swift 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)。我在 PageVC 函数中处理每个页面的转换,除了页面(VC)之外,它在转换时刻可见。一切正常。 这是我的代码示例:
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.")
}
}
也许这段代码将来会对任何人有所帮助。
关于swift - 界面转换后效果如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49496066/