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

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

    Found a great article by Marco Santarossa that shows multiple approaches to fixing. https://marcosantadev.com/calayer-auto-layout-swift/

    I used his first suggestion to reset the layer frame during viewDidLayoutSubViews() event.

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        playerLayer.frame = view.layer.bounds
    }
    

提交回复
热议问题