Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Swift中按取消按钮时,Replaykit窗口不会关闭?_Ios_Swift_Replaykit - Fatal编程技术网

Ios 在Swift中按取消按钮时,Replaykit窗口不会关闭?

Ios 在Swift中按取消按钮时,Replaykit窗口不会关闭?,ios,swift,replaykit,Ios,Swift,Replaykit,我用回放工具来记录我的屏幕,当预览屏幕弹出时,会有一个取消按钮来关闭屏幕,但它什么也不做。我让委托函数PreviewcontrollerdFinish与代码一起关闭它,但它不会消失。有人知道按“取消”时如何关闭窗口吗?谢谢 func previewControllerDidFinish(previewController: RPPreviewViewController) { print("Preview finish") // close preview window

我用回放工具来记录我的屏幕,当预览屏幕弹出时,会有一个取消按钮来关闭屏幕,但它什么也不做。我让委托函数PreviewcontrollerdFinish与代码一起关闭它,但它不会消失。有人知道按“取消”时如何关闭窗口吗?谢谢

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)
    }
}
然后当停止录制按钮调用时,将委托设置为Close

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)
    }
}

}尝试执行此委托

- (void)previewController:(RPPreviewViewController *)previewController didFinishWithActivityTypes:(nonnull NSSet<NSString *> *)activityTypes {

    [previewController dismissViewControllerAnimated:YES completion:^{

    }];
}
-(void)previewController:(RPPreviewViewController*)previewController未完成activityTypes:(非空NSSet*)activityTypes{
[预览控制器解除查看控制器激活:是完成:^{
}];
}