iPad強制橫屏下訪問相冊會奔潰的問題

解決步驟
app

1,爲 UIImagePickerController 添加類別以下spa

@interface  UIImagePickerController (LandScapeImagePicker).net

- (BOOL)shouldAutorotate;orm

- (NSUInteger)supportedInterfaceOrientations;get

@end it

#import "UIImagePickerController+LandScapeImagePicker.h"io

@implementation UIImagePickerController (LandScapeImagePicker)import



- (BOOL)shouldAutorotate {變量

    return YES;object

}


- (NSUInteger)supportedInterfaceOrientations {

    returnUIInterfaceOrientationMaskAll;

}


@end


同時在打開相冊控制類中添加以下控制代碼

bAlbumListViewStatus 全局變量  (寫單例類裏)

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info

{

    bAlbumListViewStatus = NO;

    [picker dismissViewControllerAnimated:YES completion:nil];

    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

    

    //[self uploadImageWithImage:image];


    

}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

     bAlbumListViewStatus = NO;

    [picker dismissViewControllerAnimated:NO completion:nil];

}


彈出相冊的地方代碼修改以下

  UIImagePickerController *picker = [[UIImagePickerController allocinit];

    

    picker.delegate         = self;

    picker.sourceType       = sourceType;

    picker.allowsEditing    = YES;

    bAlbumListViewStatus    = YES;//

    [self presentViewController:picker animated:YES completion:nil];


2,在app delegate裏添加方向支持


- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{

    if (bAlbumListViewStatus)//全局變量,定義是否打開相冊

        return UIInterfaceOrientationMaskAll;

    else

        return UIInterfaceOrientationMaskLandscapeLeft;


}


完成如上後便可解決了

相關文章
相關標籤/搜索