我正在使用ReplayKit
来记录屏幕变化。我创建了一个示例应用程序来测试此框架。 stopRecording
块永远不会被调用。这是Apple框架的问题吗?
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
let colors:[UIColor] = [UIColor.blue, UIColor.orange, UIColor.red, UIColor.blue]
let recorder = RPScreenRecorder.shared()
var isStarted = false
override func viewDidLoad() {
super.viewDidLoad()
let count = self.colors.count
// Do any additional setup after loading the view, typically from a nib.
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) {[weak self] (timer) in
self?.view.backgroundColor = self?.colors[Int.random(in: 0..<count)]
}
}
@IBAction func startOrStopRecorder(_ sender: Any) {
let button = sender as! UIButton
if self.isStarted{
recorder.stopRecording { (preview, error) in
print("stopped")
if let thePreview = preview {
self.show(thePreview, sender: nil)
}
}
button.setTitle("Start", for: .normal)
} else {
recorder.startRecording { (error) in
print("started")
}
button.setTitle("Stop", for: .normal)
}
self.isStarted = !self.isStarted
}
}