首页 文章

如何在iPhone中使用UIImagePickerController和UITabBar

提问于
浏览
1

我在我的应用程序中使用TabBarController . 在tabbar的一个视图中,我使用 UIImagePickerController 来选择图像 .

当我添加选择器时如下

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

imagePicker.delegate = self;

imagePicker.editing = YES;

[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];

它添加了选择器,但在选择照片时,带有“选择”和“取消”按钮的底栏会隐藏在我的标签栏下面 . 如何解决这个问题 .

3 回答

  • 1

    我没有看到这个问题 - 我有一个使用 UITabBarUIImagePickerController 的应用程序,标签栏不会遮挡图像选择器 .

    在我的视图控制器中,这是创建图像选择器的 UITabBar 's view controllers, I'之一:

    self.imagePicker = [[[UIImagePickerController alloc] init] autorelease];
    imagePicker.allowsImageEditing = NO;
    imagePicker.delegate = self;
    [self presentModalViewController:imagePicker animated:YES];
    

    看起来与您的代码非常相似,只是我将图像选择器设置为保留属性 . 标签栏设置正确吗?视图控制器是否包含在 myTabBar.viewControllers 数组中?

  • 1

    问题是您使用self作为显示模态屏幕的导航控制器 . 因此,标签栏导航控制器不知道模态屏幕应该填满整个屏幕 . 由于UIImagePickerController无法将自身调整为较小的大小,因此必须使用选项卡栏导航控制器打开呈现模态视图 .

    我使用以下代码从显示在tabbar中的导航控制器显示UIImagePickerController:

    [self.navigationController presentModalViewController:picker animated:YES];
    

    使用self.navigationController而不是self作为呈现UIImagePickerController的对象为我做了诀窍 .

  • 0

    这对我有用:

    picker.delegate = currentClassViewController;
    
    [tabBarController presentModalViewController:picker animated:YES];
    

    让你的选择调用者类拥有或有权访问你的 UITabController 变量和 presentModalViewController 对你的 tabBarController .

相关问题