UIImagePickerController在图像选择上消除父视图

Rav*_*avi 2 objective-c uitabbarcontroller uiimagepickercontroller ios

我的应用程序是基于选项卡栏的应用程序。我必须提供一个选项,用户可以在配置文件编辑屏幕中更改其配置文件图片。为此,当用户单击编辑栏按钮时,我将从配置文件屏幕中推送配置文件编辑屏幕。

UITabBarViewController --> UINavigationController -->ProfileView (UIViewController) --Push--> ProfileEditView(static UITableViewController)
Run Code Online (Sandbox Code Playgroud)

我正在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];
Run Code Online (Sandbox Code Playgroud)

和委托方法

- (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];
}
Run Code Online (Sandbox Code Playgroud)

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

谢谢,

拉基

小智 5

我当时的情况非常相似,并通过将图像选择器设置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)
}
Run Code Online (Sandbox Code Playgroud)

由于: ImagePicker消除tabBar导航控制器