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

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

    To get to playerLayer, you need to loop through videoHolderView.layer.sublayers and change each one.

    this is what I did in Swift 2.2

    if let sublayers = videoHolderView.layer.sublayers{
        for layer in sublayers where layer is AVPlayerLayer{
            layer.frame.size = ... // change size of the layer here
        }
    }
    

提交回复
热议问题