ios - 全屏查看图片时解锁方向

标签 ios swift uitableview uiimageview orientation

我的 UITableViewCell 中有一个 UIImageView。当用户点击 UIImageView 时,[IDMPhotoBrowser]( https://github.com/ideaismobile/IDMPhotoBrowser ) 会从 UIImageView 显示。该应用程序仅为纵向,但是,当在 IDMPhotoBrowser 中全屏查看照片时,我想让用户能够旋转到任何方向。

IDMPhotoBrowser 显示在 UITableViewCell 的委托(delegate) 上。委托(delegate)是带有 UITableView 的常规 UIViewController。该委托(delegate)还包含在 UINavigationController 中,后者包含在 UITabBarController 中。我尝试了许多不同的解决方案,包括扩展 IDMPhotoBrowser 并尝试添加添加对所有方向的支持的功能,我尝试在 UITabBarController 上呈现 IDMPhotoBrowser >、UINavigationController委托(delegate) UIViewController。我还尝试翻转位于 UITabBarController 子类中的 bool 值,然后在请求支持的方向的函数中引用该 bool 值,这样支持的方向会根据应用程序呈现 IDMPhotoBrowser 的时间而发生变化。没有任何效果。

除了用户正在全屏查看 IDMPhotoBrowserAVPlayerViewController 时,整个应用需要仅限于纵向。

最佳答案

创建一个 UINavigationController 父类,在 UINavigationController(parent) 中以这种方式覆盖这些方法:

override func shouldAutorotate() -> Bool {
    return true
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return self.topViewController.supportedInterfaceOrientations
}

在您的 VC 中,您希望轮换:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return .All
}

在你的 VC 中你不想被轮换:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return .AllButUpsideDown
}

然后在这个导航 Controller 中推送(或设置为根 VC 等)您的浏览器或浏览器的父 VC。

关于ios - 全屏查看图片时解锁方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37591425/

相关文章:

IOS Swift 如何更快地返回标签响应

ios - 在 UIView 的背景上设置摄像头

swift - 收到错误 : Use of unresolved identifier 'NSRectFill' , 但 __NSRectFill 有效,为什么?

swift - 检查字典是否包含 Swift 中的值

swift - 如何在 Swift 2 中将 Array<String> 添加到 Dictionary<String, AnyObject>

ios - 在 Swift 中将图像从 tableView 传递到 viewController

ios - 如何向 UITapGestureRecognizer 添加参数,以便操作函数可以访问该参数

c# - iOS 上的 Unity Google Cardboard 显示问题

ios - 处理 UITableViewcell subview 的 Action (事件)的正确方法是什么?

iphone - cellForRowAtIndexPath 中的 ReusableCellWithIdentifier 问题