我相信这是一个常见问题,如果您使用的是 iOS7 并且您的 iPad 应用程序仅是横向的,但您想使用UIImagePickerController
有来源UIImagePickerControllerSourceTypePhotoLibrary
or UIImagePickerControllerSourceTypeCamera
.
如何正确设置才能使其 100% 正常工作?并且您不会获得混合方向并避免错误“支持的方向与应用程序没有共同的方向,并且shouldAutorotate
回报YES
".
如果您的 iPad 应用程序在所有情况下都只能横向显示,只需执行以下 3 个步骤:
1)在您的应用程序委托中
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
2)创建类别标题
#import "UIViewController+OrientationFix.h"
@implementation UIViewController (OrientationFix)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
@end
3)创建类别实现
#import "UIImagePickerController+OrientationFix.h"
@implementation UIImagePickerController (OrientationFix)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
@end
注意:您不需要在任何地方导入这些类别,只需将它们与项目一起编译即可
注意:不需要在任何VC中实现这些方法
注意:无需更改 plist 支持的方向
经过测试并可在任何条件下工作
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)