我正在开发一个消息应用程序(类似于 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
视图呈现不佳)
我该如何处理?
*我不想关闭选择器然后按下SendImageViewController
,我希望SendImageViewController
将 推到相机/相机胶卷的顶部,所以当我点击后退按钮时,我会回到相机/相机胶卷视图。