我的应用程序是基于标签栏的应用程序。我必须提供一个选项,用户可以在个人资料编辑屏幕中更改他的个人资料图片。为此,当用户点击编辑栏按钮时,我从个人资料界面推送个人资料编辑屏幕
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控制器 - >选择图像 - &gt ;回到配置文件屏幕)。选择父视图后,而不是图像选择器控制器。需要关闭图像选择器控制器并选择图像后保持在同一屏幕。请帮我这个如何摆脱这....
谢谢,
Raki酒。
答案 0 :(得分: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)
}
答案 1 :(得分:0)
1.创建一个baseViewController。
2.设置框架并将baseController添加到根视图控制器视图。
3.从baseViewController中显示你的imagePickerController。
4.成功获取图像后,从superview中删除baseViewController的视图。
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];