简体   繁体   English

自由形式子视图的宽度不会扩展到设备屏幕尺寸

[英]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.

相关问题 UINavigationBar不会扩展或扩展到设备宽度 - UINavigationBar doesn't expand or extend to the device width Swift-UICollectionReusableView的子视图不适合宽度 - Swift - subview of UICollectionReusableView doesn't fit with width CSS 媒体查询不反映设备屏幕大小 - CSS media queries doesn't reflect the device screen size 当contentsize增加时,scrollview中的子视图不会展开 - Subview within the scrollview doesn't expand when contentsize increases ViewController中的tableview将宽度扩展到ipad(或大屏幕设备) - tableview in viewcontroller expand width to ipad (or larger screen device) 根据子视图以编程方式设置视图宽度大小 - Set view width size programmatically base on it's subview VStack的框架大小无法覆盖整个屏幕 - VStack's frame size doesn't fill all of the screen 如何使用Freeform Simulated Size更改scrollView的高度但不更改width - How to use Freeform Simulated Size to change height of scrollView but not width 将GMGridView添加到子视图,以便不会占据所有屏幕 - Add a GMGridView to a subview so that it doesn't take all screen 为什么UITapGestureRecognizer在keyWindow(全屏)的子视图中不起作用? - Why doesn't UITapGestureRecognizer work in subview of keyWindow (full screen)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM