【问题标题】:UIImagePickerController dismissing parent view on image selectionUIImagePickerController 关闭图像选择的父视图
【发布时间】:2015-04-20 06:06:46
【问题描述】:

我的应用程序是基于标签栏的应用程序。我必须提供一个选项,用户可以在个人资料编辑屏幕中更改他的个人资料图片。为此,当用户单击编辑栏按钮时,我正在从个人资料屏幕推送个人资料编辑屏幕。

UITabBarViewController --> UINavigationController -->ProfileView (UIViewController) --Push--> ProfileEditView(static UITableViewController)

我正在使用下面的代码展示UIImagePickerController

 UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
 imagePicker.delegate = self;
 imagePicker.allowsEditing = YES;
 // imagePicker.modalPresentationStyle = UIModalPresentationOverCurrentContext; (when i use this TabBar hiding cancel and chose buttons)
 imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
 [self presentViewController:imagePicker animated:YES completion:nil];

和委托方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    profileImage = info[UIImagePickerControllerEditedImage];
    [_choseProfilePicButton setBackgroundImage:profileImage forState:UIControlStateNormal]; 

    if ([picker isKindOfClass:[UIImagePickerController class]])
    {
        [picker dismissViewControllerAnimated:YES completion:nil];
    }
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

当我尝试选择图像并单击选择图像时,当前视图返回到配置文件屏幕(配置文件屏幕--推送--> 配置文件编辑视图--> 呈现 imagePicker 控制器--> 选择图像--> 回到配置文件屏幕)。选择父视图后将关闭而不是图像选择器控制器。选择图像后需要关闭图像选择器控制器并保持在同一屏幕上。请帮助我解决这个问题....

谢谢,

拉基。

【问题讨论】:

  • 你可以试试这个NSLog(@"%@",NSStringFromClass([picker class]));你可以检查if [picker isKindOfClass:[UIImagePickerController class]]然后关闭。
  • 我也试过了...更新了我的问题请看看...

标签: ios objective-c uitabbarcontroller uiimagepickercontroller


【解决方案1】:

我的情况非常相似,通过将图像选择器的modalPresentationStyle 设置为“OverCurrentContext”解决了这个问题:

func photoButtonPressed(sender: AnyObject) {
    let picker = UIImagePickerController()
    picker.delegate = self
    picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    picker.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
    presentViewController(picker, animated: true, completion: nil)
}

感谢: ImagePicker dismiss tabBar Nav Controller

【讨论】:

  • 非常感谢!这只是救了我!
【解决方案2】:

1.创建一个baseViewController。

2.设置框架并将baseController添加到您的根viewcontrollers视图中。

3.从 baseViewController 展示你的 imagePickerController。

4.取图成功后,从superview中移除baseViewController的view。

self.baseViewController = [[UIViewController alloc] init];

[APP_DELEGATE.rootViewController.view addSubview:self.baseViewController.view];

[self.baseViewController.view autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsFromString(@"0,0,0,0")];
//You can also set frame ,I have used purelayout so the above step

[self.baseViewController presentViewController: self.myPicker.imagePickerController animated:YES completion:^ {}];


//Last step after picking up image
[self.baseViewController.view removeFromSuperview];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多