2016-10-09 34 views
3

在一個快速的應用程序中,我想在等待10秒後用相機開始錄製視頻。在x秒後觸發iPhone視頻錄製

一旦10秒等待已經結束,這個函數被調用:

func startRecording() { 
    // trigger video recording 
} 

到目前爲止,當用戶在「記錄視頻按鈕」點擊後,顯示在相機界面,然後用戶必須點擊內置錄音鍵:

@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.") 
     } 
    } 

我想要做的,是自動觸發錄像,「錄音錄像按鍵」 10秒鐘之後被擊中。

我找不到有關如何「觸發」錄製的信息。 有沒有辦法做到這一點?

感謝您的幫助

回答

1

你可以呈現UIImagePickerController後補充一點:

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