I implemented a local video player which supports both non-full screen and full screen mode, with a toggle full screen button on the bottom right corner of the videoPlayerView. I added a subview called controlsContainerView to include play/pause button, the slider, the two labels and the toggle full screen button as well. I also added a tapGesture recognizer to get user tapping gesture on the videoPlayerView in order to handle weather or not the controlsContainerView should be shown. Here comes my question:
On non full screen mode, everything works perfectly. On clicking the toggle full screen button, the videoPlayerView rotates 90 degrees and expand to full screen, while video is playing. However, the controls container view disappeared, no matter if I tap the screen of not. I print out the isHidden status of the controlsContainerView and it changes between "true" and "false", which it should. The frame size and position is good as well. But it doesn't show up visually.
func handleFullScreen() {
controlsContainerView.removeFromSuperview()
if isFullScreen {
fullScreenBtn.setImage(UIImage(named: "full_screen"), for: .normal)
UIView.animate(withDuration: 3, animations: {
let width = UIApplication.shared.keyWindow?.frame.width
let height = width!*9/16
self.transform = CGAffineTransform(rotationAngle: 0)
self.frame = CGRect(x: 0, y: 0, width: width!, height: height)
})
} else {
fullScreenBtn.setImage(UIImage(named: "full_screen_exit"), for: .normal)
UIView.animate(withDuration: 3, animations: {
self.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)
self.frame = UIScreen.main.bounds
self.controlsContainerView.frame = self.bounds
self.playerLayer.frame = self.bounds
})
}
isFullScreen = !isFullScreen
}
func handleControlsContainerViewHide() {
print("Tapped")
if controlsContainerViewIsHidden {
controlsContainerView.isHidden = false
} else {
controlsContainerView.isHidden = true
}
controlsContainerViewIsHidden = !controlsContainerViewIsHidden
print(controlsContainerView.isHidden)
}
func setupVideoControlView() {
//setupGradientLayer()
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleControlsContainerViewHide)))
controlsContainerView.frame = bounds
addSubview(controlsContainerView)
// Sub views of controls container view, I deleted the layout constraints since they are irrelevant to this question.
controlsContainerView.addSubview(activityIndicatorView)
controlsContainerView.addSubview(pausePlayBtn)
controlsContainerView.addSubview(fullScreenBtn)
controlsContainerView.addSubview(videoLengthLabel)
controlsContainerView.addSubview(currentTimeLabel)
controlsContainerView.addSubview(videoSlider)
controlsContainerView.addSubview(closeBtn)
}
Thanks for reading my question and hope you can get me some insights!