ios – 在Swift中按取消按钮时,Replaykit窗口不会被忽略?

我使用重播工具包来记录我的屏幕,当预览屏幕弹出时,有一个取消按钮来关闭屏幕,但它没有做任何事情.我有委托func previewControllerDidFinish与代码解雇它但它不会消失.按取消时有谁知道如何关闭窗口?谢谢!

func previewControllerDidFinish(previewController: RPPreviewViewController) {
    print("Preview finish")

        // close preview window
        previewController.dismissViewControllerAnimated(true, completion: nil)
    }

最佳答案 在swift 3.2中

第一:

class ViewController: UIViewController, RPPreviewViewControllerDelegate {

func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
        previewController.dismiss(animated: true, completion: nil)
    }
}

然后当停止录制按钮调用时,并设置委托关闭

if RPScreenRecorder.shared().isRecording {
RPScreenRecorder.shared().stopRecording { (previewController: RPPreviewViewController?, error: Error?) in
    if previewController != nil {
        let alertController = UIAlertController(title: "Recoring", message: "Do you wish to discard or view your recording?", preferredStyle: .alert)
        let discardAction = UIAlertAction(title: "Discard", style: .destructive, handler: nil)

        let viewAction = UIAlertAction(title: "View", style: .default, handler: { (action: UIAlertAction) in

            // set delegate here
            previewController?.previewControllerDelegate = self

            self.present(previewController!, animated: true, completion: nil)
        })

        alertController.addAction(discardAction)
        alertController.addAction(viewAction)
        self.present(alertController, animated: true, completion: nil)
    }
}

}

点赞