我实现了一个本地视频播放器,它支持非全屏和全屏模式,并在videoPlayerView的右下角有一个切换全屏按钮。我添加了一个名为controlsContainerView的子视图,包括播放/暂停按钮,滑块,两个标签以及切换全屏按钮。我还添加了一个tapGesture识别器,以便在videoPlayerView上获取用户点击手势,以便处理天气或不显示controlsContainerView。这是我的问题:
在非全屏模式下,一切都很完美。单击切换全屏按钮时,videoPlayerView将旋转90度并在视频播放时扩展为全屏。但是,无论我是否点击屏幕,控件容器视图都会消失。我打印出controlsContainerView的isHidden状态,它在“true”和“false”之间切换,它应该是。框架尺寸和位置也很好。但它并没有在视觉上显现出来。
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)
}
感谢您阅读我的问题,希望您能给我一些见解!
答案 0 :(得分:0)
对不起,我是个傻瓜。我自己手动删除了controlsContainerView,这正是它没有出现的原因。