[英]Freeform subview’s width doesn’t expand to device screen size
I'm trying to add a music miniplayer view controller to a container UITabBarVC.我正在尝试将音乐迷你播放器视图 controller 添加到容器 UITabBarVC。 The music miniplayer view controller is a freeform storyboard file.
音乐迷你播放器视图 controller 是一个自由格式的 storyboard 文件。 I am implementing the file as follows:
我正在执行该文件,如下所示:
self.miniPlayerViewController = self.storyboard?.instantiateViewController(with: MiniPlayerViewController.identifier)
self.miniPlayerViewController.view.frame = CGRect(x: 0, y: self.customBottomOffset, width: UIScreen.main.bounds.width, height: 92)
This exists in a function which I execute in viewDidLoad().这存在于我在 viewDidLoad() 中执行的 function 中。
On larger devices, such as an iPhone 8 Plus (below), the miniplayer doesn't expand to fit the screen's width despite me using UIScreen.main.bounds.width as the width parameter.在较大的设备上,例如 iPhone 8 Plus(下图),尽管我使用 UIScreen.main.bounds.width 作为宽度参数,但迷你播放器不会扩展以适应屏幕的宽度。 Any suggestions on how to fix this?
对于如何解决这个问题,有任何的建议吗?
Update Tried setting View width to Now Playing View width, but didn't help the situation.更新尝试将视图宽度设置为正在播放视图宽度,但没有帮助解决这种情况。
Turns out that this was due to how I was rounding the corners of the miniplayer.事实证明,这是由于我如何绕过迷你播放器的角落。 Guess executing this code under didSet did not allow the view to actually register the size of the screen:
猜测在 didSet 下执行此代码不允许视图实际注册屏幕大小:
@IBOutlet weak var nowPlayingView: UIView! {
didSet {
nowPlayingView.roundCorners(corners: [.topLeft, .topRight], radius: 20.0)
}
}
I would appreciate if anyone could please explain this further.如果有人能进一步解释这一点,我将不胜感激。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.