ios – 仅在一个ViewController中旋转
发布时间:2020-12-15 01:44:06 所属栏目:百科 来源:网络整理
导读:我正在尝试旋转一个视图,而所有其他视图(5)都固定为纵向.原因是在一个视图中我希望用户观看他之前保存的图片.我想这是可能的,但到目前为止,我无法弄清楚如何实现这一目标.任何人都可以帮忙或给我一个暗示吗? 我正在使用在iOS8上运行的Swift编程 解决方法 这
我正在尝试旋转一个视图,而所有其他视图(5)都固定为纵向.原因是在一个视图中我希望用户观看他之前保存的图片.我想这是可能的,但到目前为止,我无法弄清楚如何实现这一目标.任何人都可以帮忙或给我一个暗示吗?
我正在使用在iOS8上运行的Swift编程 解决方法
这适用于Swift 3和Swift 4.您可以在AppDelegate.swift中使用以下代码:
func application(_ application: UIApplication,supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { guard let rootViewController = self.topViewControllerWithRootViewController(rootViewController: window?.rootViewController),(rootViewController.responds(to: Selector(("canRotate")))) else{ // Only allow portrait (standard behaviour) return .portrait; } // Unlock landscape view orientations for this view controller return .allButUpsideDown; } private func topViewControllerWithRootViewController(rootViewController: UIViewController!) -> UIViewController? { guard rootViewController != nil else { return nil } guard !(rootViewController.isKind(of: (UITabBarController).self)) else{ return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UITabBarController).selectedViewController) } guard !(rootViewController.isKind(of:(UINavigationController).self)) else{ return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UINavigationController).visibleViewController) } guard !(rootViewController.presentedViewController != nil) else{ return topViewControllerWithRootViewController(rootViewController: rootViewController.presentedViewController) } return rootViewController } 你可以在原帖中了解更多:http://www.jairobjunior.com/blog/2016/03/05/how-to-rotate-only-one-view-controller-to-landscape-in-ios-slash-swift/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |