Supported orientations has no common orientation with the application, and shoul

本文提供了解决使用UIImagePickerController时遇到的竖屏不支持问题的方法,包括在Info.plist中设置程序支持Portrait,并通过自定义的controller来支持特定的屏幕类型。详细步骤如下:首先,在Info.plist中添加程序支持Portrait;其次,创建一个继承类继承UIImagePickerController,重写shouldAutorotate、shouldAutorotateToInterfaceOrientation和supportedInterfaceOrientations方法,以支持竖屏。

在调用UIImagePickerController出现这个错误的解决办法:
Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
在Info.plist里需要设置程序支持Portrait,同时编写一个继承类继承UIImagePickerController。

@interface NonRotatingUIImagePickerController : UIImagePickerController
@end

@implementation NonRotatingUIImagePickerController
- (BOOL) shouldAutorotate
{
    return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
    return UIInterfaceOrientationMaskAllButUpsideDown;
    //return UIInterfaceOrientationMaskLandscape;
#endif
}
@end

 
原因是UIImagePickerController默认是竖屏,所以程序需要支持竖屏,然后通过自定义的controller来支持具体的屏幕类型。

<think>嗯,用户遇到了iOS应用中KSAdNavigationController的旋转方向冲突问题,具体是出现了“no commonorientation”的异常。我需要先理解这个问题的背景。通常,当视图控制器之间的旋转方向不一致时,系统会抛出这个异常。用户可能是在自定义导航控制器KSAdNavigationController时,重写了旋转相关的属性或方法,导致与子控制器或父控制器的方向设置冲突。 首先,我应该回忆一下iOS旋转方向的处理机制。每个视图控制器都可以通过supportedInterfaceOrientations方法指定支持的旋转方向,而系统会通过协调父控制器和子控制器的方向来找到共同的支持方向。如果找不到,就会报错。用户的问题可能出在KSAdNavigationController的supportedInterfaceOrientations返回了错误的方向,或者子控制器的方向设置与它不兼容。 接下来,我需要检查用户提供的引用内容。引用[2]提到恢复路径必须唯一,但可能和旋转方向问题无关。不过引用[1]提到根视图控制器的设置,这可能影响整个应用的旋转行为,如果KSAdNavigationController是根控制器,那么它的旋转设置会影响所有子控制器。此外,引用[4]提到Xamarin.Forms的抽象方式,但用户的问题是关于原生iOS的,所以可能不相关。用户需要解决的是KSAdNavigationController的旋转冲突。可能的解决方案包括:1.确保KSAdNavigationController的supportedInterfaceOrientations方法返回正确的方向,可能根据当前顶部的子控制器动态调整。例如,重写该方法,返回当前topViewController的支持方向。 2.检查子控制器是否正确地指定了supportedInterfaceOrientations,确保它们和导航控制器兼容。如果有子控制器不支持导航控制器声明的方向,就会导致冲突。 3.检查是否在Info.plist中正确设置了应用支持的所有方向,避免遗漏必要方向。 另外,可能需要覆盖shouldAutorotate方法,返回YES允许自动旋转。同时,确保所有相关的控制器(导航控制器和子视图控制器)在方向设置上协调一致,避免出现没有交集的情况。 用户可能已经尝试过一些方法,但仍有问题。需要提醒他们检查各个控制器的实现,特别是导航控制器和当前活动子控制器的方向设置是否冲突。此外,使用调试工具查看异常发生的具体上下文,比如哪个控制器导致了方向不匹配。最后,生成相关问题需要考虑用户可能进一步的问题,比如如何动态调整方向、处理特定控制器的旋转,或者调试旋转问题的方法。</think>### KSAdNavigationController旋转方向冲突解决方案 #### 问题分析 当KSAdNavigationController与子视图控制器在旋转方向设置不一致时,系统会抛出"no common orientation"异常。这通常由以下原因导致: 1. 导航控制器与子控制器支持的设备方向无交集 2. 未正确覆盖旋转控制方法 3. Info.plist中声明方向与代码实现不一致 #### 分步解决方案 **1. 统一方向配置** ```swift override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return topViewController?.supportedInterfaceOrientations ?? .portrait } override var shouldAutorotate: Bool { return topViewController?.shouldAutorotate ?? false } ``` 此实现可确保导航控制器方向与当前活动子控制器保持一致[^2] **2. 子控制器明确声明方向** ```swift class ChildViewController: UIViewController { override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .portrait } } ``` **3. Info.plist配置验证** 确保在项目配置中勾选所有可能使用的方向: ``` <key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> </array> ``` **4. 异常处理机制** ```swift func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return .all } ``` #### 调试建议 1. 使用Xcode的视图层级调试器检查控制器层次结构 2. 在控制台过滤"Supported orientations has no common orientation"日志 3. 使用断点验证各控制器的supportedInterfaceOrientations返回值
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值