//试试这个代码希望它有帮助:
func startRecording() { 让记录器 = RPScreenRecorder.shared()
if #available(iOS 9.0, *) {
recorder.startRecording(withMicrophoneEnabled: true) { [unowned self] (error) in
if let unwrappedError = error {
print(unwrappedError.localizedDescription)
} else {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Stop", style: .plain, target: self, action: #selector(PreviewVC.stopRecording))
}
}
} else {
// Fallback on earlier versions
}
}
func stopRecording() { 让记录器 = RPScreenRecorder.shared()
recorder.stopRecording { [unowned self] (preview, error) in
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Start", style: .plain, target: self, action: #selector(PreviewVC.startRecording))
if let unwrappedPreview = preview {
unwrappedPreview.previewControllerDelegate = self
self.present(unwrappedPreview, animated: true, completion: nil)
}
}
}
func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
self.dismiss(animated: true, completion: nil)
}