gpt4 book ai didi

Swift - 全屏时 ControlContainerView 从 VideoPlayerView 中消失

转载 作者:行者123 更新时间:2023-11-30 12:20:13 24 4
gpt4 key购买 nike

我实现了一个本地视频播放器,它支持非全屏和全屏模式,在 videoPlayerView 的右下角有一个切换全屏按钮。我添加了一个名为controlsContainerView 的 subview ,其中包括播放/暂停按钮、 slider 、两个标签以及切换全屏按钮。我还添加了一个 tapGesture 识别器来让用户在 videoPlayerView 上点击手势,以便处理天气或不显示controlsContainerView。我的问题来了:

在非全屏模式下,一切正常。单击切换全屏按钮后,videoPlayerView 会在视频播放时旋转 90 度并扩展到全屏。但是,无论我是否点击屏幕,控件容器 View 都会消失。我打印出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)

}

感谢您阅读我的问题,希望您能给我一些见解!

最佳答案

对不起,我傻了。我自己手动删除了controlsContainerView,这正是它没有显示的原因。

关于Swift - 全屏时 ControlContainerView 从 VideoPlayerView 中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44877298/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com