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

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:^{
  
}];

}

你可能感兴趣的:(拍照,获取系统相册,更改头像)