我正在使用UIImagePickerController来选择照片和裁剪图像。
这与以下情况相同 https://forums.developer.apple.com/thread/88286
这是我的代码:
- (void) onTest:(UIButton *)btn {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.delegate = self;
picker.allowsEditing = YES;
[picker setModalPresentationStyle: UIModalPresentationOverCurrentContext];
[self presentViewController:picker animated:YES completion:nil];
}
这是视图层。我没有添加这个UIView。 我无法按下取消按钮,我无法放大/缩小。
iOS 10没有问题。我只遇到iOS 11的问题。
答案 0 :(得分:1)
我有个好主意解决这个问题。
将控制器(从中显示UIImagePickerController
)设置为UIImagePickerController
的委托,然后符合UINavigationControllerDelegate
,因为UIImagePickerController
是{{1}的子类然后实现方法:
UINavigationController
答案 1 :(得分:0)
- (IBAction)addPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
使用此委托: -
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
答案 2 :(得分:0)
使用此代码打开照片库:
UIImagePickerController *pickerView = [[UIImagePickerController alloc] init];
pickerView.allowsEditing = YES;
pickerView.delegate = self;
[pickerView setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:pickerView animated:YES completion:nil];
使用此委托将裁剪后的图像传送给视图控制器:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
UIImage *image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}