我试图从图像选择器中选择一个图像后创建一个模态视图控制器.我用的代码是:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"Picker has returned");
[self dismissModalViewControllerAnimated:YES];
// TODO: make this all threaded?
// crop the image to the bounds provided
img = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"orig image size: %@", [[NSValue valueWithCGSize:img.size] description]);
// save the image, only if it's a newly taken image:
if([picker sourceType] == UIImagePickerControllerSourceTypeCamera){
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
// self.image_View.image=img;
//self.image_View.contentMode = UIViewContentModeScaleAspectFit;
ModalViewController *sampleView = [[ModalViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到警告:
Warning: Attempt to present <ModalViewController: 0x7561600> on <ViewController: 0x75a72e0> while a presentation is in progress!
Run Code Online (Sandbox Code Playgroud)
并且不显示模态视图.
我究竟做错了什么?
Mox*_*oxy 28
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
// TODO: make this all threaded?
// crop the image to the bounds provided
img = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"orig image size: %@", [[NSValue valueWithCGSize:img.size] description]);
// save the image, only if it's a newly taken image:
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
// self.image_View.image = img;
// self.image_View.contentMode = UIViewContentModeScaleAspectFit;
NSLog(@"Picker has returned");
[self dismissViewControllerAnimated:YES
completion:^{
ModalViewController *sampleView = [[ModalViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}];
}
Run Code Online (Sandbox Code Playgroud)
这里的问题正在发生,因为你首先解雇了,UIImagePicker
并立即将另一个视图显示为模态视图.这就是你得到这个错误的原因.
请检查以下代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:NO completion:^{
img = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"orig image size: %@", [[NSValue valueWithCGSize:img.size] description]);
if([picker sourceType] == UIImagePickerControllerSourceTypeCamera)
{
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
ModalViewController *sampleView = [[ModalViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
27808 次 |
最近记录: |