日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于手机横屏打开相机或者相册闪退解决方案

發布時間:2024/4/17 编程问答 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于手机横屏打开相机或者相册闪退解决方案 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天遇到一個需求就是在手機橫屏的時候要打開相冊相機,但是在打開的手就報錯,經過一上午的查資料,看文檔,知道了問題所在,原來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

總結

以上是生活随笔為你收集整理的关于手机横屏打开相机或者相册闪退解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。