- (void)showUploadSheet {
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"上传" message:@"选择图片的方式" preferredStyle:UIAlertControllerStyleActionSheet];
[alertVC addAction:[UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIImagePickerController *pickVC = [[UIImagePickerController alloc] init];
pickVC.delegate = self;
pickVC.allowsEditing = YES;
pickVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:pickVC animated:YES completion:nil];
}]];
[alertVC addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alertVC animated:YES completion:nil];
}
上面的关键在于 pickVC.allowsEditing = YES; 这个属性
这个属性表示选了图片以后支持拖动图片,选择裁剪范围
同时要注意的是,选择完以后一定要Dismiss掉PickerViewController,否则界面会卡住不能操作。
猜测是由于点击Choose选择以后,系统自动调取了编辑页面的popViewControllerAnimated:方法,(从动画可以看出,编辑页面就是通过push的方式压入栈内的),但是编辑页VC的nav应该是由PickerViewController的上一个VC传递过来的,所以如果PickerViewController没有Dismiss掉,那就会导致界面卡在编辑页面
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
DLOG(@"image:%@",info);
UIImage *image = info[UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil];
}
网友评论