在cameraOverlayView上拍照

时间:2012-02-06 11:01:42

标签: iphone xcode uiimagepickercontroller custom-view

我的问题; 隐藏默认的相机控件并使用我自己的相机控件覆盖它。这是使用属性cameraOverlayView进行的。我也遇到了触发takePicture方法的问题。

1 个答案:

答案 0 :(得分:0)

(问题已在评论和编辑中解决。请参阅Question with no answers, but issue solved in the comments (or extended in chat)

OP写道:

  

以下是解决方案:

     

我有两个UIViewController。主ViewController和CustomOverlay(用于摄像机控件)。

     

我是ViewController我声明了源类型和可能相机控制的叠加,如下所示:

- (void)viewDidLoad
{
    // notification from the CustomOverlay Controller that triggers the eTakePicture method
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eTakePicture:) name:@"eTakePicture" object:nil];

    daysBtn.delegate = self;
    daysBtn.hidden = YES;

    picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    picker.showsCameraControls = NO;
    picker.navigationBarHidden = YES;
    picker.wantsFullScreenLayout = YES;
    picker.delegate = self;

    overlay = [[CustomOverlay alloc] initWithNibName:@"CustomOverlay" bundle:nil];
    // Overlay for the camera controls, note the "= overlay.view", the ".view" was important
    // because the overlay is a new UIViewcontroller (with xib) so you have to call the
    // view. Most tutorials that I saw were based on UIView so only "= overlay" worked.
    picker.cameraOverlayView = overlay.view;
    [self presentModalViewController:picker animated:NO];

    [super viewDidLoad];
}
  

现在在CustomOverlay上,这是一个UIViewController我有拍照按钮,并希望这个按钮触发主ViewController中的方法:

- (IBAction)shoot:(id)control {

    [[NSNotificationCenter defaultCenter] postNotificationName:@"eTakePicture" object:self];

}
  

回到主ViewController:

-(void)eTakePicture:(NSNotification *)notification
{
    [picker takePicture];
}
  

一旦我查看,上面的所有代码都会改变一点,特别是我必须要检查cameraSourceType是否可用的第一个块。

     

希望能帮到那里的人。有问题,请问。