我在开发的时候,在做一个调用相册的项目,要求是横屏,所以iPhone、iPad都是横屏,两者调用相册的代码还不一样(这点大家注意哦!)我吧代码贴一下吧。
- (IBAction)openPictureLibFromSaved:(id)sender {
//获取图片选取器
UIImagePickerController *imagePicker = [[UIImagePickerControlleralloc]init];
UIPopoverController *popC = [[UIPopoverControlleralloc]initWithContentViewController:imagePicker];
//指定代理
imagePicker.delegate =self;
//打开图片后允许编辑
imagePicker.allowsEditing =YES;
[imagePickershouldAutorotate];
imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
if ([[UIDevicecurrentDevice].modelhasPrefix:@"iPad"]) {
NSLog(@"ipad");
[popC presentPopoverFromRect:CGRectMake(0,0,200,200)inView:self.viewpermittedArrowDirections:UIPopoverArrowDirectionLeftanimated:YES];
}elseif ([[UIDevicecurrentDevice].modelhasPrefix:@"iPhone"]){
NSLog(@"iphone");
[selfpresentViewController:imagePickeranimated:NOcompletion:^{}];
}
}
关键的时候来了,这个时候运行在iPhone上面,会出现崩溃,
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES
在iOS6 之后,解决办法是:
在appdelegate添加
#if __IPAD_OS_VERSION_MAX_ALLOWED >= __IPAD_6_0
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAll;
}
我试了,反正成功了,你呢?
如果觉得好就点赞,如果觉得帮你解决了问题,你就评论一下哦!
如果你觉得有什么不对!或者你遇到新的问题,可以联系我哦!留言定回。
2015.07.09追加:
最近也遇到开发横屏幕应用需要调用相册的问题,经过研究的确发现之前的结论存在问题,于是继续研究,发现两个解决途径,1、在调用相册开始给发送一个通知,支持UIInterfaceOrientationMaskAll,在调用即将结束时发送通知UIInterfaceOrientationLandscape。
2、iOS8之后使用AssetsLibrary.framework.很好使!贴一段代码:
Initialization and presentation
let pickerController = DKImagePickerController()
pickerController.pickerDelegate = self
self.presentViewController(pickerController, animated: true) {}
Delegate methods
func imagePickerControllerCancelled() {
self.dismissViewControllerAnimated(true, completion: nil)
}
func imagePickerControllerDidSelectedAssets(assets: [DKAsset]!) {
for (index, asset) in enumerate(assets) {
}
self.dismissViewControllerAnimated(true, completion: nil)
}
Configurable properties
/// The height of the bottom of the preview
var previewHeight: CGFloat = 80
var rightButtonTitle: String = "确定"
/// Displayed when denied access
var noAccessView: UIView