ios – ViewWillTransitionToSize在Swift 3中爆发了吗?

前端之家收集整理的这篇文章主要介绍了ios – ViewWillTransitionToSize在Swift 3中爆发了吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我旋转设备时,我正在使用viewWillTransitionToSize调整我的滑出菜单,但它似乎在 Swift 3中被打破了?有人能为我解决这个问题吗?我的代码如下所示:
  1. func viewWillTransitionToSize(size: CGSize,withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
  2. super.viewWillTransition(to: size,with: coordinator)
  3. coordinator.animate(alongsideTransition: nil,completion: {
  4. _ in
  5.  
  6. let controller = self.revealViewController().rightViewController
  7.  
  8. var frame = controller?.view.frame
  9. frame?.size.height = UIScreen.main.bounds.size.height - self.navigationController!.navigationBar.frame.size.height - self.toolBar.frame.size.height - (UIApplication.shared.isStatusBarHidden ? 0 : 20)
  10. controller?.view.frame = frame!
  11. })
  12. }

看起来我在旋转设备时没有被调用

解决方法

弄清楚问题是什么,迁移到swift 3所做的更改是不正确的,并且函数应该如下所示:
  1. override func viewWillTransition(to size: CGSize,with coordinator: UIViewControllerTransitionCoordinator) {
  2. super.viewWillTransition(to: size,completion: {
  3. _ in
  4.  
  5. let controller = self.revealViewController().rightViewController
  6.  
  7. var frame = controller?.view.frame
  8. frame?.size.height = UIScreen.main.bounds.size.height - self.navigationController!.navigationBar.frame.size.height - self.toolBar.frame.size.height - (UIApplication.shared.isStatusBarHidden ? 0 : 20)
  9. controller?.view.frame = frame!
  10. })
  11.  
  12. }

猜你在找的iOS相关文章