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

前端 未结 13 900
小蘑菇
小蘑菇 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:32

    Actually you shouldn't add AVPlayer's layer as a sublayer. Instead of that you should use the following method, in the subclass of view in which you want to display AVPlayer.

    + (Class)layerClass
    {
         return [AVPlayerLayer class];
    }
    

    And use the following line to add(set) the player layer.

    [(AVPlayerLayer *)self.layer setPlayer:self.avPlayer];
    

    Hope it helps;-)

提交回复
热议问题