我正在尝试旋转一个视图,而所有其他视图(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 -迅速/