AVPlayer layer inside a view does not resize when UIView frame changes

前端 未结 13 876
小蘑菇
小蘑菇 2020-12-23 17:08

I have a UIView which contains an AVPlayer to show a video. When changing orientation, I need to change the size and location of the video.

<
13条回答
  •  眼角桃花
    2020-12-23 17:36

    theDunc's answer did not work for me. I found a solution that is more simple: I just needed to adjust the frame of the AVPlayerLayer after changing it in the UIView:

    avPlayerLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    

    In this blog is stated, that a View's frame also affect that of the layer in it.

    When you change a view’s frame, it’s simply changing the layer’s frame.

    For this case, it is not true.

提交回复
热议问题