ios - UIImagePickerController 在图像选择时关闭父 View

标签 ios objective-c uitabbarcontroller uiimagepickercontroller

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

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];

和委托(delegate)方法

- (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];
}

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

谢谢,

拉基。

最佳答案

我只是处于非常相似的情况,通过将图像选择器的 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

关于ios - UIImagePickerController 在图像选择时关闭父 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29740352/

相关文章:

UITextView 中带有 <blockquote> 标签的 HTML

java - 带有 Appium 的 iOS Web 测试

iphone - 将函数移动到 objective-c 中的后台线程

ios - 在 Swift 中以编程方式设置时配置文件选项卡栏图像像素化

c# - 在 xamarin.ios 中的 View Controller 之间传递数据

ios - 如何以编程方式创建多个按钮和操作?

ios - NsNumberFormatter 没有给出正确的结果

objective-c - 将 App Delegate 连接到 Controller 类

ios - 在 iOS 中渲染圆圈的最佳技术是什么?

iphone - 第二次点击时未设置 UITabBarItem 上的自定义背景