iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 仅在一个ViewController中旋转大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_772_3@概述 我正在尝试旋转一个视图,而所有其他视图(5)都固定为纵向.原因是在一个视图中我希望用户观看他之前保存的图片.我想这是可能的,但到目前为止,我无法弄清楚如何实现这一目标.任何人都可以帮忙或给我一个暗示吗? 我正在使用在iOS8上运行的Swift编程 这适用于Swift 3和Swift 4.您可以在AppDelegate.swift中使用以下代码: func application(_ applica
我正在尝试旋转一个视图,而所有其他视图(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/

大佬总结

以上是大佬教程为你收集整理的ios – 仅在一个ViewController中旋转全部内容,希望文章能够帮你解决ios – 仅在一个ViewController中旋转所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。