动画AVPlayerLayer变换属性

时间:2019-03-27 15:42:52

标签: ios swift avfoundation core-animation avplayerlayer

我不会用AVPlayerLayer重现实时照片变焦效果。为此,我使用VideoView

class VideoView: UIView {
    override class var layerClass: AnyClass {
        return AVPlayerLayer.self
    }

    var playerLayer: AVPlayerLayer {
        return layer as! AVPlayerLayer
    }

    var player: AVPlayer? {
        get {
            return playerLayer.player
        }

        set {
            playerLayer.player = newValue
        }
    }
}

问题是,每当我尝试在视频播放期间更改视图或图层的transform属性时,都不会改变。但是更改将在播放完成后稍后应用。

动画示例:

func zoomIn() {
    UIView.animate(
        withDuration: 0.2,
        delay: 0,
        options: .allowAnimatedContent,
        animations: {
            self.transform = .init(scaleX: 1.1, y: 1.1)
    },
        completion: { _ in
    })
}

1 个答案:

答案 0 :(得分:0)

似乎AVPlayerLayer会忽略许多CALayer属性,并且缩放VideoView的唯一方法是更改​​其frame