0

我在 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)

}
4

2 回答 2

1

您应该将最后一行从:

previewController.dismiss(animated: true, completion: nil)

到:

dismiss(animated: true, completion: nil)
于 2017-01-10T05:13:36.627 回答
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)
}
于 2017-08-10T13:25:38.343 回答