Ich versuche, eine Kamera-App zu erstellen, die mehr oder weniger wie die Standard-Kamera-App fungieren würde. Das Ding, das im Moment für mich nicht funktioniert, ist Tippen auf den Fokus. Ich möchte, dass sich die Kamera fokussiert und alles tut, was sie an meinem berührten Punkt tut, genau wie die echte Kamera-App.ios AVFoundation tippen, um zu fokussieren
Hier ist mein viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
// Session
_session = [[AVCaptureSession alloc] init];
_session.sessionPreset = AVCaptureSessionPresetPhoto;
// Input
_videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
_videoInput = [AVCaptureDeviceInput deviceInputWithDevice:_videoDevice error:nil];
// Output
_frameOutput = [[AVCaptureVideoDataOutput alloc] init];
_frameOutput.videoSettings = [NSDictionary dictionaryWithObject:AVVideoCodecJPEG forKey:AVVideoCodecKey];
[_frameOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
[_session addInput:_videoInput];
[_session addOutput:_frameOutput];
[_session startRunning];
};
Und hier ist die Methode, die meine Kamera Fokus Sachen auf Klick machen sollte.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
UITouch *touch = obj;
CGPoint touchPoint = [touch locationInView:touch.view];
focusLayer.frame = CGRectMake((touchPoint.x-25), (touchPoint.y-25), 50, 50);
if ([_videoDevice isFocusPointOfInterestSupported]) {
NSError *error;
if ([_videoDevice lockForConfiguration:&error]) {
[_videoDevice setFocusPointOfInterest:touchPoint];
[_videoDevice setExposurePointOfInterest:touchPoint];
[_videoDevice setFocusMode:AVCaptureFocusModeAutoFocus];
if ([_videoDevice isExposureModeSupported:AVCaptureExposureModeAutoExpose]){
[_videoDevice setExposureMode:AVCaptureExposureModeAutoExpose];
}
[_videoDevice unlockForConfiguration];
}
}
// NSLog(@"x = %f, y = %f", touchPoint.x, touchPoint.y);
}];
}
Nichts passiert wirklich, sobald ich auf den Bildschirm klicke.
Gibt es eine Dokumentation oder etwas, das erklärt, warum dies so gemacht werden muss? – spacecash21
Die Antwort wurde aktualisiert, um auf die Dokumentation von Apple zu verweisen. –
Sie können auch 'AVCaptureVideoPreviewLayer' verwenden und es ist' captureDevicePointOfInterestForPoint' Methode, um den Fokuspunkt zu berechnen. – Legoless