iPhone 相机不显示

标签 iphone ios uiimagepickercontroller

我在操作表中使用 ios 相机时遇到了尴尬的问题:当用户触摸“图片按钮”时,操作表会显示两个选项(使用照片库中的照片或使用相机)。

无论我选择什么选项,都没有任何反应,但当我再次选择媒体类型时,它会起作用。

下面是我的代码:

 - (IBAction)selectMediaType: (id)sender {
    [appDelegate hideTabBar];
    UIActionSheet *action = [[UIActionSheet alloc] 
                             initWithTitle: nil
                             delegate:self 
                             cancelButtonTitle:@"Fechar" 
                             destructiveButtonTitle: nil 
                             otherButtonTitles:@"Galeria", @"Tirar Foto", nil];

    [action showFromTabBar: appDelegate.tabController.tabBar];
}


- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        NSArray *mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];

        imagePicker.delegate = self;
        imagePicker.hidesBottomBarWhenPushed = YES;
        imagePicker.mediaTypes = mediaTypes;
        imagePicker.allowsEditing = NO;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentModalViewController:imagePicker animated:YES];
        imagePicker.hidesBottomBarWhenPushed = YES;
    } else if (buttonIndex == 1) {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            NSArray *mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];

            imagePicker.delegate = self;
            imagePicker.mediaTypes = mediaTypes;
            imagePicker.allowsEditing = YES;
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;

            [self presentModalViewController:imagePicker animated:YES];
        } else {
            UIAlertView *alert = [[UIAlertView alloc] 
                                  initWithTitle:@"" 
                                  message:@"Your device does not support this feature!" 
                                  delegate:self 
                                  cancelButtonTitle:@"OK" 
                                  otherButtonTitles: nil];
            [alert show];
            [alert release];

        }
    } else {
        [appDelegate showTabBar];
    }
}



- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *image;
    NSURL *mediaURL;

    mediaURL = (NSURL *) [info valueForKey:UIImagePickerControllerMediaURL];

    if (mediaURL == nil) {
        image = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];
    }

    imageView.image = image;

    [picker dismissModalViewControllerAnimated:YES];

    [appDelegate showTabBar];
}

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [picker dismissModalViewControllerAnimated:YES];

    [appDelegate showTabBar];
}

谁能帮我解决这个问题?

谢谢。

最佳答案

我明白了。

基本上这是一个内存泄漏问题:我正在切换 View ,在 super View 中添加 subview (而不是在当前 View 中),但我没有从 super View 中删除旧的,所以我遇到了内存泄漏;)

关于iPhone 相机不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10088740/

相关文章:

iphone - 我可以使用 UIImagePickerController 拍多张照片吗?

iphone - 我如何以编程方式通过点击图像进行转义?

ios - 在 Cordova 构建 ios 期间找不到团队 ID 的代码签名错误

iphone - 将 UIWebView 委托(delegate)属性设置为 nil

iphone - UIWebView的setKeyboardAppearance

ios - 'dump' 核心数据堆栈的最佳方法?

ios - 如何拍照并将其传递给另一个 View Controller

ios - UICollectionView 的 UICollectionViewCell 中的图像在滚动后以编程方式创建重叠

ios - indexPath.row 在静态或滚动时更新不正确

ios - 为 UIImagePicker 设置委托(delegate)返回错误