我使用重播工具包来录制我的屏幕,当预览屏幕弹出时,会有一个取消按钮来关闭屏幕,但它没有做任何事情。我有代理func previewControllerDidFinish与代码来解雇它但它并没有消失。按取消时有谁知道如何关闭窗口?谢谢!
func previewControllerDidFinish(previewController: RPPreviewViewController) {
print("Preview finish")
// close preview window
previewController.dismissViewControllerAnimated(true, completion: nil)
}
答案 0 :(得分:1)
在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)
}
}
}
答案 1 :(得分:1)
尝试实现此委托
- (void)previewController:(RPPreviewViewController *)previewController didFinishWithActivityTypes:(nonnull NSSet<NSString *> *)activityTypes {
[previewController dismissViewControllerAnimated:YES completion:^{
}];
}