iPhone SDK - 如何使用自定义相机视图拍摄照片?

时间:2010-07-18 16:47:27

标签: iphone cocoa-touch camera iphone-sdk-3.1.3

我想在用户选中屏幕时立即释放快门。我有工作代码以全屏模式显示相机。如何通过触摸触发快门?

- (IBAction) takePicture
{
    if (!self.imgPicker) {
        self.imgPicker = [[UIImagePickerController alloc] init];
        self.imgPicker.allowsEditing = NO;
        self.imgPicker.delegate = self;
    }

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        self.imgPicker.showsCameraControls = NO;
        self.imgPicker.wantsFullScreenLayout = YES;

        CGAffineTransform cameraTransform = CGAffineTransformMakeScale(1.132, 1.132);
        self.imgPicker.cameraViewTransform = cameraTransform;

        UIView *headsUpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];

        [self.imgPicker setCameraOverlayView:headsUpView];
    } else {
        NSLog(@"Camera not available.");
        self.imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;  
    }

    [self presentModalViewController:self.imgPicker animated:YES];
}

1 个答案:

答案 0 :(得分:2)

您应该使用takePicutre方法,然后检测屏幕上的任何触摸。

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/occ/instm/UIImagePickerController/takePicture

像这样的东西

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = [[event allTouches] anyObject];
    self.imgPicker.takePicture;
}