IOS 横屏中添加UIImagePickerController获取系统图片

今天写ipad的项目,然后需要调用系统相册选择图片,然后用了UIImagePickerController ,崩溃了,后来查了一下,UIImagePickerController只支持竖屏,但是。。。

我竟然找到了一个解决的方法:

这是因为 UIImagePickerController只支持竖屏的原因。
解决:

1、在AppDelegate.m中添加


?
1
2
3
4
5
#if __IPAD_OS_VERSION_MAX_ALLOWED >= __IPAD_6_0
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
     return UIInterfaceOrientationMaskAll;
}
#endif
这样一般的就解决问题了,再不行话继续
在该viewController和上一层的viewController中添加


?
1
2
3
4
5
6
7
8
9
10
11
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation ==  UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==  UIInterfaceOrientationLandscapeRight );
}
 
-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}
 
- (BOOL)shouldAutorotate {
    return YES;
}
原文地址:https://www.cnblogs.com/niit-soft-518/p/4366506.html