swift - Swift:上一个视图在淡入到具有不同方向的视图时旋转
问题描述
我之前的视图 ( CaptureVC ) 不会自动旋转,因此它只有纵向。我的第二个观点是它过渡到(ManageCaptureVC)确实会自动旋转,并且当它正在淡入淡出过渡到它时,如果设备处于横向状态,CaptureVC 会在淡出时突然旋转。如何避免或补偿这种情况?
更彻底地说,它是一个缩放动画,然后是一个淡入淡出的动画到新的视图控制器(ManageCaptureVC):
UIView.animate(withDuration: 0.3, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: {
self.view.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
}, completion: { (finished: Bool) in
// Here is where CaptureVC rotates while fading into ManageCaptureVC
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionFade
transition.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseIn)
self.present(manageCaptureVC, animated: false, completion: nil)
})
在我的应用程序委托中,我覆盖了这两个函数:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if let rootViewController = self.topViewControllerWithRootViewController(rootViewController: window?.rootViewController) {
if (rootViewController.responds(to: Selector(("canRotate")))) {
// Unlock landscape view orientations for this view controller if it is not currently being dismissed
if !rootViewController.isBeingDismissed{
return .all
}
}
}
// Only allow portrait (standard behaviour)
return .portrait
}
private func topViewControllerWithRootViewController(rootViewController: UIViewController!) -> UIViewController? {
if (rootViewController == nil) {
return nil
}
if (rootViewController.isKind(of: UITabBarController.self)) {
return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UITabBarController).selectedViewController)
} else if (rootViewController.isKind(of: UINavigationController.self)) {
return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UINavigationController).visibleViewController)
} else if (rootViewController.presentedViewController != nil) {
return topViewControllerWithRootViewController(rootViewController: rootViewController.presentedViewController)
}
return rootViewController
}
我添加了ManageCaptureVC:
@objc func canRotate(){}
这样它就可以响应自动旋转。
解决方案
推荐阅读
- reactjs - 选项下拉菜单未显示在子组件中
- bash - 如何将`ls -l`的输出解析为bash中的多个变量?
- java - ChromeDriver 未通过 Java ZAP API 代理本地流量
- android - 如何以编程方式从应用程序中单击 Android“后退按钮”?
- sql - 在 PostgreSQL 中插入后计算平均值
- html - 如何隐藏属于 div 但显示在另一个 div 上的内容?
- python - BeautifulSoup webscraping find_all():排除元素作为最后一个元素附加
- python - ray `num_cpus` 是否用于实际分配 CPU?
- python-3.x - 为什么我不能使用卡方检验拟合泊松分布?装修有什么问题?
- amazon-web-services - 如何在云形成模板中使用 Fn::If 和数组值