Whenever I change the frame of my AVPlayerLayer, the video is not resized immediately, but animated to the new size.
For example: I change the frame from (0, 0, 100, 100) to (0, 0, 400, 400), the view's frame is changed immediately, but the video's size is animated to the new size.
Has anyone encountered this issue? And if yes does someone know a way to disable the default animation?
Thanks!
Here is what I do in Swift right after changing the
playerLayer
'sframe
:Probably this, what will help in some cases:
adding custom 'setFrame:' setter in view that holds the player layer
You can try disabling implicit actions and using zero length animations:
The easiest and cleanest way to deal with this is to create a UIView subclass that has AVPlayerLayer as its layerClass. When doing this the AVPlayerLayer will behave just like a regular UIView layer. You can change the frame of the view instead of the layer and no implicit animations will happen.
AVPlayerLayerView.h
AVPlayerLayerView.m
You can now do this:
To associate the AVPlayerLayer with an AVPlayer simply do this:
This is what I used:
I hope this helps. I don't know if its best practices, but it works for me. It seems that whenever ".frame" or "setFrame" is used, it adds animation to the layer.
Do you use ?: