Ios 如何在Swift中取消预览UI控制器?
我不明白为什么它不被解雇。我在我的应用程序中使用replaykit,我试图关闭录制完屏幕后弹出的UI。在左上方有一个取消按钮,当我按下它时,预览控制器不会关闭。有一个委托函数可以关闭控制器,但它对我不起作用。我觉得这很容易解决,但我不确定我做错了什么。请帮帮我。如果你需要更多信息,请告诉我。谢谢大家!Ios 如何在Swift中取消预览UI控制器?,ios,swift,Ios,Swift,我不明白为什么它不被解雇。我在我的应用程序中使用replaykit,我试图关闭录制完屏幕后弹出的UI。在左上方有一个取消按钮,当我按下它时,预览控制器不会关闭。有一个委托函数可以关闭控制器,但它对我不起作用。我觉得这很容易解决,但我不确定我做错了什么。请帮帮我。如果你需要更多信息,请告诉我。谢谢大家! func startRecoding() { if RPScreenRecorder.sharedRecorder().available { RPScreenRecorder.sh
func startRecoding() {
if RPScreenRecorder.sharedRecorder().available {
RPScreenRecorder.sharedRecorder().startRecordingWithMicrophoneEnabled(true, handler: { (error: NSError?) -> Void in
if error == nil { // Recording has started
} else {
// Handle error
}
})
} else {
// Display UI for recording being unavailable
}
}
func stopRecording() {
RPScreenRecorder.sharedRecorder().stopRecordingWithHandler { (previewController: RPPreviewViewController?, error: NSError?) -> Void in
if previewController != nil {
let alertController = UIAlertController(title: "Recording", message: "Do you wish to discard or view your gameplay recording?", preferredStyle: .Alert)
let discardAction = UIAlertAction(title: "Discard", style: .Default) { (action: UIAlertAction) in
RPScreenRecorder.sharedRecorder().discardRecordingWithHandler({ () -> Void in
// Executed once recording has successfully been discarded
})
}
let viewAction = UIAlertAction(title: "View", style: .Default, handler: { (action: UIAlertAction) -> Void in
self.view?.window?.rootViewController?.presentViewController(previewController!, animated: true, completion: nil)
})
alertController.addAction(discardAction)
alertController.addAction(viewAction)
self.view?.window?.rootViewController!.presentViewController(alertController, animated: true, completion: nil)
} else {
// Handle error
}
}
}
func previewControllerDidFinish(previewController: RPPreviewViewController) {
previewController.dismissViewControllerAnimated(true, completion: nil)
}
您需要确保为预览视图控制器设置了代理
RPScreenRecorder.sharedRecorder().stopRecordingWithHandler { (previewController: RPPreviewViewController?, error: NSError?) -> Void in
if previewController != nil {
// Try adding this line
previewController.delegate = self
//
let alertController = UIAlertController(title: "Recording", message: "Do you wish to discard or view your gameplay recording?", preferredStyle: .Alert)
.
.
.
请显示用于显示您现在试图取消的视图的代码。好的,我将更新op。我更新了代码,您现在可以查看它。您正在做什么来设置视图控制器的委托?是否调用PreviewcontrollerdFinish?好的,那么我在PreviewcontrollerdFinish中放置了什么?您可以这样做。或者,您可以使用按钮触发的方法解除。