0

I have two views

One is container of AVPlayerLayer like this

containerView.layer.addSublayer(playerLayer)

and containerView has own auto layout about superview

self.view.addSubview(containerView)
containerView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
containerView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
containerView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
containerView.heightAnchor.constraint(equalToConstant: 300).isActive = true

so i override viewDidLayoutSubviews()

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    playerLayer.frame = containerView.frame
}

and second view is custom playback control view on containerView

containerView.addSubview(playBackControlView)
playBackControlView.leftAnchor.constraint(equalTo: containerView.leftAnchor).isActive = true
playBackControlView.rightAnchor.constraint(equalTo: containerView.rightAnchor).isActive = true
playBackControlView.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
playBackControlView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true

and there are several views like UIButton, UISlider etc

Here is my question

when i tapped one of buttons on playBackControlView which called enlargeScreenButton how can make my containerView, playBackControlView and AVPlayerLayer gonna be a full screen like landscape mode at once

I read this question already but only playerLayer changed, not whole view

(I will not device rotation)

I did many thing on Stackoverflow but they were fit on my case

if i transform some views are broken and if i change frame with UIScreen.main.bounds also it broke some views

PrepareFor
  • 2,448
  • 6
  • 22
  • 36
  • I'm not saying you can't do what you're doing, but why not use [AVPlayerViewController?](https://developer.apple.com/documentation/avkit/avplayerviewcontroller) It manages fullscreen for you. – Aaron Apr 04 '18 at 03:35

1 Answers1

0

I'd suggest you create a PlayerView subclass with custom layer view as such:

class PlayerView: UIView
    override class var layerClass: AnyClass {
        return AVPlayerLayer.self
    }
}

This way you'll be able to manipulate the view without caring about the sublayer and it's animation. Then you'd be able to use the animations similar to ones from the answer you mentioned, but on the view. With all the subviews added using auto layout - you should be good to go and they should change accordingly when you animate using UIView.animate

Alexander Telegin
  • 665
  • 1
  • 7
  • 22