UIAlertController * alter = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIImagePickerController * pickImage = [[UIImagePickerController alloc]init];
pickImage.allowsEditing = YES;
pickImage.delegate = self;
__weak typeof(self)weakSelf = self;
UIAlertAction * actionXiangCe = [UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
pickImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[weakSelf presentViewController:pickImage animated:YES completion:nil];
}];
UIAlertAction * actionXiangJi = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
pickImage.sourceType = UIImagePickerControllerSourceTypeCamera;
[weakSelf presentViewController:pickImage animated:YES completion:nil];
}else{
}
}];
UIAlertAction * actionCancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[weakSelf dismissViewControllerAnimated:YES completion:nil];
}];
[alter addAction:actionXiangJi];
[alter addAction:actionXiangCe];
[alter addAction:actionCancle];
[self presentViewController:alter animated:YES completion:nil];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info{
UIImage * newphoto = [info objectForKey:@"UIImagePickerControllerEditedImage"];