iOS 横屏调用相册 之 iPhone 也崩溃

 我在开发的时候,在做一个调用相册的项目,要求是横屏,所以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

 

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值