AVPlayerLayer resizing

1.2k views Asked by At

I am currently working on a detachable AVPlayer so you can drag it with a pan gesture and drop it in predefined drop zones on your UIWindow. (I know iOS 9 will do that for me...but I have to do it on iOS 8)

I did all the work (moving & decreasing/increasing the size of the UIView where is located the player) and it's working well with the UIView. However, the AVPlayerLayer inside this view is really jerky when I move/change the size the UIView at the same time.

So here is the question: How can I update the layer's frame in a smooth way ? I tried using the setNeedsDisplayOnBoundsChange, by setting it to YES. And I also tried implementing the layoutSublayersOfLayer in which I set the AVPlayerLayer's frame to the UIView's bounds.

Both ended up with lags and really not smooth gestures.

NB: In a really basic project sample, it's working like a charm. (Nothing else in the app besides 2 view controllers, one presenting the player, and there I can start dragging it in the UIWindow...it's perfect). However, in my current application, the player is also presented above everything else, and the gesture is really jerky on the layer only. The rest of the application is made of multiple view controllers but nothing is executed while I am using the player.

Does someone have an idea on how to make it working perfectly? Thank you :)

EDIT: I am using autolayout. The parent view of the AVPlayerLayer has 4 constraints: top, leading, width, height.... the 4 of them are updated each time you drag it using the pangesture. The UIView has the correct values.

0

There are 0 answers