0

我正在使用MPRemoteCommandCenter锁定屏幕的滑块。有没有办法像普通的 UISlider 一样观察.began、、、和?.moved.ended.cancelled

var obs: NSKeyValueObservation?

commandCenter.changePlaybackPositionCommand.isEnabled = true
commandCenter.changePlaybackPositionCommand.addTarget { [weak self] (event) -> MPRemoteCommandHandlerStatus in

    guard let event = event as? MPChangePlaybackPositionCommandEvent else { return .commandFailed }

    let eventPositionTime: TimeInterval = event.positionTime
    // do whatever with time

    self?.obs = event.observe(KeyPath<MPChangePlaybackPositionCommandEvent, Value>, options: NSKeyValueObservingOptions, changeHandler: { (MPChangePlaybackPositionCommandEvent, NSKeyValueObservedChange,<Value>) in

        // in here observe .began, .moved, ,ended, .cancelled
    })
}
4

0 回答 0