0

iOS 6.1上,我在UITabBar的一个选项卡中以非模态方式显示UIImagePickerController

在我的初始化中:

self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
self.picker.delegate = self;
self.picker.allowsEditing = NO;
[self.view addSubview:self.picker.view];

我已经实现:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    return;
}

因为我从来没有打电话:

[picker presentViewController:(UIViewController *) animated:(BOOL) completion:^(void)completion];

我不需要打电话:

[picker dismissViewControllerAnimated:NO completion:nil];

但是,当我按下取消按钮时,取消按钮显示为灰色,并且UIImagePickerController似乎锁定了。一些控件有效,例如图像/视频开关和倒车摄像头按钮,但拍照按钮被冻结。

如果我转到另一个选项卡并返回“相机”选项卡,则UIImagePickerController将被重置并再次正常。在这种情况下执行的唯一代码是viewWillAppearviewDidAppear,它们不应该与这种情况相关。

iOS 7上,按下取消按钮时没有任何锁定。

由于UIImagePickerController始终显示在选项卡中,因此我真的不需要取消按钮,所以我将如何:

  • 隐藏或禁用取消按钮
  • 实施imagePickerControllerDidCancel这样事情就不会锁定
4

1 回答 1

0

实现了一个相机叠加视图,一切正常。

    self.picker = [[UIImagePickerController alloc] init];
    self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
    self.picker.delegate = self;
    self.picker.allowsEditing = NO;
    self.picker.showsCameraControls = NO;

    UIView *clearView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    clearView.opaque = NO;
    clearView.backgroundColor = [UIColor clearColor];

    UIToolbar *toolBar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-self.tabBarController.tabBar.frame.size.height-55, self.view.frame.size.width, 55)];
    toolBar.barStyle =  UIBarStyleBlackOpaque;
    NSArray *items=[NSArray arrayWithObjects:
                    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(takePicture)],
                    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                    nil];
    [toolBar setItems:items];

    UIView *overlayView = [[UIView alloc] initWithFrame:self.view.bounds];
    [overlayView addSubview:clearView];
    [overlayView addSubview:toolBar];

    [self.picker setCameraOverlayView:overlayView];

    [self.view addSubview:self.picker.view];

[[UIBarButtonItem alloc] ... action:@selector(takePicture)],

- (void)takePicture
{
    [self.picker takePicture]; // triggers didFinishPickingMediaWithInfo
}

UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    if (image != nil)
    {
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    }
}
于 2014-09-23T20:55:16.537 回答