使用AVCam 演示,我试图通过在 AVCamViewController.m 中进行以下更改,在实际拍摄照片之前添加 5 秒的延迟:
- (IBAction)captureStillImage:(id)sender
{
// Capture a still image
[[self stillButton] setEnabled:NO];
// delay picture capture by 5 seconds
myTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0
target: self
selector: @selector(pictureTimer:)
userInfo: nil
repeats: NO];
}
- (void) pictureTimer: (NSTimer *) timer {
[[self captureManager] captureStillImage];
}
但是,AVCamCaptureManager::captureStillImage 中的完成处理程序似乎从未被调用(我从未看到“captureStillImage 完成处理程序”日志消息):
- (void) captureStillImage
{
AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
if ([stillImageConnection isVideoOrientationSupported])
[stillImageConnection setVideoOrientation:orientation];
NSLog(@"captureStillImage");
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
NSLog(@"captureStillImage completion handler");
这不会使用 NSTimer 工作吗?