拍照,获取系统相册,更改头像

pragma mark - 相机 相册

  • (void)actionSheetClickedButtonAtSourceType:(UIImagePickerControllerSourceType)sourceType{

    // 跳转到相机或相册页面
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    // 判断是否支持相机
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        imagePickerController.delegate = self;
        
        if (sourceType == UIImagePickerControllerSourceTypeCamera) {
            
               imagePickerController.allowsEditing = NO;
        }else{
        
                imagePickerController.allowsEditing = YES;
            
        }
       
        imagePickerController.sourceType = sourceType;
        
    }

    [self presentViewController:imagePickerController animated:YES completion:^{
        
    }];
}

pragma mark - 相册 代理 方法

  • (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    RSMeTableViewHeaderView * header = [self.view viewWithTag:1000];

    //如果是 相机,直接弹出 方框
    if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {

      [JKImageClipTool showWithImage:image isSquare:NO autoSavaToAlbum:NO complete:^(UIImage *image) {
          
          [header setIconImage:image];
          
      }];
      
    
      //如果是相册 直接 选中更改头像
    

    }else if(picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {

      [header setIconImage:image];
    

    }

[picker dismissViewControllerAnimated:YES completion:^{
  
}];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容