I wan't to reproduce Live Photo zoom effect with AVPlayerLayer
. For this purpose I use 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
}
}
}
The problem is, that whenever I try to change transform
property of the view or of the layer during the video playback, nothing changes. But the changes are applied later after the playback finishes.
Animation example:
func zoomIn() {
UIView.animate(
withDuration: 0.2,
delay: 0,
options: .allowAnimatedContent,
animations: {
self.transform = .init(scaleX: 1.1, y: 1.1)
},
completion: { _ in
})
}
Seems like AVPlayerLayer
ignores many of CALayer
properties and the only way to scale a VideoView
is to change it's frame
.