我在swift 2中使用了这个代码并且它有效。但是现在在Swift 3中,当我按下取消或保存按钮时,在录制结束时弹出的预览控制器窗口不会被忽略。我究竟做错了什么?
func stopRecording() {
let sharedRecorder = RPScreenRecorder.shared()
sharedRecorder.stopRecording(handler: { (previewController: RPPreviewViewController?, error) in
if previewController != nil {
print("stopped recording")
self.previewViewController.previewControllerDelegate = self
self.view?.window?.rootViewController?.present(previewController!, animated: true, completion: nil)
}
func previewControllerDidFinish(previewController: RPPreviewViewController) {
previewController.dismiss(animated: true, completion: nil)
}
答案 0 :(得分:1)
您应该更改最后一行:
previewController.dismiss(animated: true, completion: nil)
为:
dismiss(animated: true, completion: nil)
答案 1 :(得分:1)
//试试这段代码希望它有所帮助:
func startRecording() {
let recorder = 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() {
let recorder = 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)
}