关于手机横屏打开相机或者相册闪退解决方案
生活随笔
收集整理的這篇文章主要介紹了
关于手机横屏打开相机或者相册闪退解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天遇到一個需求就是在手機橫屏的時候要打開相冊相機,但是在打開的手就報錯,經過一上午的查資料,看文檔,知道了問題所在,原來UIImagePickerController 只支持豎屏
?解決思路
1,讓UIImagePickerController 支持橫屏
2 ,在打開相機的時候讓項目橫豎屏,在關閉相機或者相冊的時候還原 讓項目只支持橫屏。
3 在appdelegate 通過通知來切換屏幕的橫豎屏 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ return _MyInterfaceOrientationMask; }
appdelegate里面 @property (nonatomic,assign) NSInteger MyInterfaceOrientationMask;- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch._MyInterfaceOrientationMask = UIInterfaceOrientationMaskLandscapeRight;[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeRotate:) name:@"changeRotate" object:nil];return YES; } - (void)changeRotate:(NSNotification *)noti{if ([noti.object isEqualToString:@"0"]) {_MyInterfaceOrientationMask = UIInterfaceOrientationMaskLandscapeRight;}else{_MyInterfaceOrientationMask = UIInterfaceOrientationMaskAll;} } - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{return _MyInterfaceOrientationMask; } view里面 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{[[NSNotificationCenter defaultCenter] postNotificationName:@"changeRotate" object:@"1"];ownPickViewController *picker = [[ownPickViewController alloc] init];picker.delegate = self;if (buttonIndex==0) {picker.sourceType = UIImagePickerControllerSourceTypeCamera;[self presentViewController:picker animated:YES completion:nil];}else if(buttonIndex==1) {picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;[self presentViewController:picker animated:YES completion:nil];}}- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{[[NSNotificationCenter defaultCenter] postNotificationName:@"changeRotate" object:@"0"];[picker dismissModalViewControllerAnimated:NO]; } //實現圖片選擇器代理//參數:圖片選擇器 字典參數-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{[[NSNotificationCenter defaultCenter] postNotificationName:@"changeRotate" object:@"0"];//通過key值獲取到圖片 UIImage * image =info[UIImagePickerControllerOriginalImage];NSLog(@"image=%@ info=%@",image, info);//判斷數據源類型if (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {}}重新的 UIImagePickerController 里面加一個 -(BOOL)shouldAutorotate{ return YES;}?
轉載于:https://www.cnblogs.com/ZhangShengjie/p/6248772.html
總結
以上是生活随笔為你收集整理的关于手机横屏打开相机或者相册闪退解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 添加网络打印机
- 下一篇: Qt Qwdget 汽车仪表知识点拆解4