iOS 6.1-如何为非模态UIImagePickerController实现ImagePickerCollerDidC



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

在我的init:中

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

但是,当我按下Cancel按钮时,CancelIImagePickerController似乎已锁定。有些控件可以工作,如图像/视频开关和倒车摄像头按钮,但拍照按钮被冻结。

如果转到另一个选项卡并返回"相机"选项卡,则UIImagePickerController将重置并再次正常工作。在这种情况下执行的唯一代码是viewWillAppearViewDidPear

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

由于UIImagePickerController总是显示在选项卡中,所以我真的不需要取消按钮,所以我该怎么做呢:

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

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

    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分配]。。。操作:@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);
    }
}

相关内容

  • 没有找到相关文章

最新更新