解决步骤
1,为 UIImagePickerController 添加类别如下
UIImagePickerController (LandScapeImagePicker)
- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
#import "UIImagePickerController+LandScapeImagePicker.h"
@implementation UIImagePickerController (LandScapeImagePicker)
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
returnUIInterfaceOrientationMaskAll;
}
同时在打开相册控制类中添加如下控制代码
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 alloc] init];
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;
}
完成如上后即可解决了