gpt4 book ai didi

ios - subview 的框架向下移动

转载 作者:行者123 更新时间:2023-11-28 13:17:04 25 4
gpt4 key购买 nike

我正在尝试设置一个覆盖整个屏幕的 View 。我设置了 frame = uiView.frame 但顶部似乎有一个空间并且 frame center 似乎被向下推了。有没有办法强制 View 适合实际框架?

代码:

func showActivityIndicator(uiView: UIView) {
container.frame = uiView.frame
container.center = uiView.center
container.backgroundColor = UIColor.blueColor() //UIColorFromHex(0xffffff, alpha: 0.3)

loadingView.frame = CGRectMake(0, 0, 80, 80)
loadingView.center = uiView.center
loadingView.backgroundColor = UIColorFromHex(0x444444, alpha: 0.7)
loadingView.clipsToBounds = true
loadingView.layer.cornerRadius = 10

activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
activityIndicator.center = CGPointMake(loadingView.frame.size.width / 2, loadingView.frame.size.height / 2);

loadingView.addSubview(activityIndicator)
container.addSubview(loadingView)
uiView.addSubview(container)
activityIndicator.startAnimating()
}

图片(将背景颜色设置为蓝色以显示我的意思)

enter image description here

最佳答案

为了覆盖整个屏幕,您需要将 View 添加到主 UIWindow,否则它将始终位于选项卡栏和导航栏下方。也无需设置中心和框架。只需确保 subview 框架等于父 View 边界(而不是框架)。请参阅此处以获取解释:UIView frame, bounds and center

试试这个:

    // Get the main window
let window: UIWindow = (UIApplication.sharedApplication().windows.first as UIWindow)

// Match the size of the overlay view to the window
container.frame = window.bounds

// Add it to the window as a subview
window.addSubview(overlayView)

如果您想在导航栏下方添加加载指示器覆盖层,只需将其添加到 View Controller View 即可。此代码假定它在 View Controller 内运行(因此 self = View Controller )

    container.frame = self.view.bounds
self.view.addSubview(container)

关于ios - subview 的框架向下移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28602716/

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