在窗口中将 UITableViewController 的 UIActivityIndi​​catorView 居中,而不是在表视图中 [英] Center a UIActivityIndicatorView for a UITableViewController in the window, not in the table view

查看:22
本文介绍了在窗口中将 UITableViewController 的 UIActivityIndi​​catorView 居中,而不是在表视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在界面设计器中的表格视图中有一个 UIActivityIndi​​catorView.我正在尝试使用以下方法将其居中在屏幕中间:

I have a UIActivityIndicatorView to my table view in the interface designer. I am trying to center it in the middle of the screens using the following:

   override func viewWillLayoutSubviews() {
        self.activityView.center = self.view.center
    }

但它似乎总是在页面上的位置太低",它似乎位于 UITableView 的中间,而不是像我想要的那样位于窗口中间(即它被导航栏等)

But it always seems to be sitting too 'low' on the page, it appears to be centered in the middle of the UITableView, not in the middle of the window like I want (ie. It is getting pushed down by the navigation bar etc)

推荐答案

使用自动布局,您可以使用 layoutMarginsGuideUITableView 中获得正确的中心 X、Y 锚点>s 和 UICollectionViews:

Using auto layout, you can use layoutMarginsGuide to get the right center X, Y anchor in both UITableViews and UICollectionViews:

activityView.translatesAutoresizingMaskIntoConstraints = false
activityView.centerXAnchor.constraint(equalTo: view.layoutMarginsGuide.centerXAnchor).isActive = true
activityView.centerYAnchor.constraint(equalTo: view.layoutMarginsGuide.centerYAnchor).isActive = true

这篇关于在窗口中将 UITableViewController 的 UIActivityIndi​​catorView 居中,而不是在表视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆