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


    今天遇到一个需求就是在手机横屏的时候要打开相册相机,但是在打开的手就报错,经过一上午的查资料,看文档,知道了问题所在,原来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;}
  • 相关阅读:
    好的软件架构设计(转)
    利用ManualResetEvent来来控制异步调用的打印的线程的暂停和恢复(转)
    Lucene.Net+盘古分词器(详细介绍)(转)
    如何让 height:100%; 起作用---父级元素必须设定高度
    前端问题汇总
    JS基础_强制类型转换-Number
    CSS实现垂直居中的常用方法
    vue项目上线步骤
    一篇文章全面了解运维监控知识体系
    vue+axios 前端实现登录拦截(路由拦截、http拦截)
  • 原文地址:https://www.cnblogs.com/ZhangShengjie/p/6248772.html
Copyright © 2020-2023  润新知