- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self getMediaFromSource:UIImagePickerControllerSourceTypeCamera];
}
- (IBAction)TakePhoto:(id)sender {
[self getMediaFromSource:UIImagePickerControllerSourceTypeCamera];
}
- (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = sourceType;
[self presentModalViewController:picker animated:YES];
[picker release];
}
#pragma mark - UIImagePickerController delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[picker dismissModalViewControllerAnimated:YES];
[self.tabBarController setSelectedIndex:1];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
[self.tabBarController setSelectedIndex:1];
}
更新了 B 部分。cameraOverlayView 的示例代码
- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
self.imagePickerController.sourceType = sourceType;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
// user wants to use the camera interface
//
self.imagePickerController.showsCameraControls = NO;
if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0)
{
// setup our custom overlay view for the camera
//
// ensure that our custom view's frame fits within the parent frame
CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0,
CGRectGetHeight(overlayViewFrame) -
self.view.frame.size.height - 10.0,
CGRectGetWidth(overlayViewFrame),
self.view.frame.size.height + 10.0);
self.view.frame = newFrame;
[self.imagePickerController.cameraOverlayView addSubview:self.view];
}
}
}
http://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010196
我建议使用“cameraOverlayView”来尝试创建某种伪导航栏,其中交互将按您的预期工作。
“您可以自定义一个图像选择器控制器来自己管理用户交互。为此,请提供一个包含您要显示的控件的覆盖视图,并使用“捕获静止图像或电影”中描述的方法。您可以显示自定义覆盖视图作为默认控件的补充或替代。UIImagePickerController 类的自定义覆盖视图在 iOS 3.1 及更高版本中通过 cameraOverlayView 属性可用。有关代码示例,请参阅 PhotoPicker 示例代码项目。
重要 UIImagePickerController 类仅支持纵向模式。此类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改,但有一个例外。您可以将自定义视图分配给 cameraOverlayView 属性,并使用该视图来呈现附加信息或管理相机界面和代码之间的交互。”
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html