从UIImagePickerController摄像头视图中推送viewController

时间:2012-07-22 15:26:20

标签: iphone objective-c ios uiimagepickercontroller

我正在开发一个消息传递应用程序(类似于WhatsApp),用户可以相互发送文本和图像消息。

当用户想要发送图像时,他可以从相机胶卷中选择一个,或者他可以用相机拍摄一个。

这就是我为两种情况提供UIImagePickerController的方式:

- (void)handleTakePhoto
{
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];

    ipc.delegate = self;
    ipc.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentModalViewController:ipc animated:YES];
    [ipc release];
}

- (void)handleChooseFromLibrary
{
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.delegate = self;
    ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    NSString *desired = (NSString *)kUTTypeImage;
    if ([[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary] containsObject:desired]) {
        ipc.mediaTypes = [NSArray arrayWithObject:desired];
    }

    [self presentModalViewController:ipc animated:YES];
    [ipc release];
}

在用户选择/拍照后,我正在推动SendImageViewController全屏显示图像,并有一个实际发送图像的按钮。

这是我推动它的方式:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];


    SendImageViewController *sivc = [[SendImageViewController alloc] initWithImage:image
                                                                          delegate:self];
    [picker pushViewController:sivc animated:YES];
    [sivc release];
}  

当我从相机胶卷推SendImageViewController时,一切都很好。 问题是,当从相机拍摄图像时,我无法按下SendImageViewController,因为相机没有导航栏(我试图推动它,但我的SendImageViewController视图没有t表示良好)

我该如何处理?

* 我不想解雇选择器,然后按SendImageViewController,我希望将SendImageViewController推到相机/相机胶卷的顶部,所以当我点按后退按钮时,我会回到相机/相机胶卷视图。

1 个答案:

答案 0 :(得分:14)

尝试按以下方式显示导航栏:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];

[picker setNavigationBarHidden:NO animated:YES];
[picker pushViewController:vc animated:YES];