x 秒后触发 iphone 视频录制

Trigger iphone video recording after x seconds

在 swift 应用程序中,我想在等待 10 秒后开始用相机录制视频。

一旦 10 秒等待结束,将调用此函数:

func startRecording() {
  // trigger video recording
}

到目前为止,当用户点击一个"Record video button",它会显示相机界面,然后用户必须点击内置的录制按钮:

@IBAction func recordVideo(sender: AnyObject) {
        if (UIImagePickerController.isSourceTypeAvailable(.Camera)) {
            if UIImagePickerController.availableCaptureModesForCameraDevice(.Rear) != nil {
                imagePicker.sourceType = .Camera
                imagePicker.mediaTypes = [kUTTypeMovie as String]
                imagePicker.allowsEditing = false
                imagePicker.delegate = self
                locationManager.startUpdatingLocation()
                print(locationManager.location)
                presentViewController(imagePicker, animated: true, completion: {})
            } else {
                postAlert("Rear camera doesn't exist", message: "Application cannot access the camera.")
            }
        } else {
            postAlert("Camera inaccessible", message: "Application cannot access the camera.")
        }
    }

我想做的是在 "Record video button" 被击中 10 秒后自动触发录音。

我找不到有关如何 "trigger" 录音的信息。 有办法做到这一点吗?

感谢您的帮助

您可以在提交 UIImagePickerController 后添加:

imagePicker.performSelector(#selector(UIImagePickerController.startVideoCapture), withObject: nil, afterDelay: 10)