To change the size of the AVPlayerLayer that was addedSublayer due to the size change of the UIView when the screen was rotated

Asked 2 years ago, Updated 2 years ago, 33 views

Constraint changes the size of the UIView(view1) that is present when rotating the screen in swift.
However, the size of the AVPlayerLayer that you add to the UIView does not automatically change.

// Some of the following sources:
// Generate View.
let videoPlayerView = AVPlayerView (frame:view1.bound)
// Make the layer of the UIView AVPlayerLayer.
letlayer=videoPlayerView.layer as!AVPlayerLayer
layer.videoGravity=AVLayerVideoGravity.resizeAspect
layer.player=videoPlayer
// add layers
view1.layer.addSublayer(layer)

I would like to change the layer of the above source when UIview(view1) changes.When rotating the screen, click

override var shouldAutorotate:Bool{}
override var supportedInterfaceOrients:UIInterfaceOrientationMask{}

I think it can be handled by , but how can I change the size of the AVPlayerLayer that I added in addSubLayer?

Please let me know if you know.

swift

2022-09-30 16:24

1 Answers

With the above source, isn't the layer property of AVPlayerView tied to videoPlayerView?

Therefore, instead of taking out only the layers and not addSubLayer, create and apply NSLayoutConstraint to view1 honestly and view1 to AVPode>view1 in InterfaceBuilderI think that would be better.)


2022-09-30 16:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.