PeriodicTimeObserver & Animation - PullRequest
       54

PeriodicTimeObserver & Animation

0 голосов
/ 13 декабря 2018

У меня есть AVPlayer и UIView в UICollectionViewCell.UIView перемещается при нажатии.Если я добавляю periodTimeObserver (щелкните изображение воспроизведения), UIView возвращается в исходное положение. Как я могу это исправить?

enter image description here

https://im4.ezgif.com/tmp/ezgif-4-d3ffd4565338.gif

    func addPeriodicTimeObserver() {
    // Invoke callback every second
    let interval = CMTime(seconds: 1.0,
                          preferredTimescale: CMTimeScale(NSEC_PER_SEC))
    // Queue on which to invoke the callback
    let mainQueue = DispatchQueue.main
    // Add time observer
    var timeObserverToken = player.addPeriodicTimeObserver(forInterval: interval, queue: mainQueue) {
            [weak self] time in
            // update player transport UI

        let seconds = CMTimeGetSeconds(time)
        let secondsString = String(format: "%02d", (Int(seconds) % 60))
        let minutesString = String(format: "%02d", (Int(seconds) / 60))

        self!.videoCurrentLabel.text = "\(minutesString):\(secondsString)"


        // move the slider thumb
        if let duration = self?.player.currentItem?.duration {
            let durationSeconds = CMTimeGetSeconds(duration)

            self!.videoSlider.value = Float(seconds / durationSeconds)

        }

    }
}
...