在窗口中将 UITableViewController 的 UIActivityIndicatorView 居中,而不是在表视图中 [英] Center a UIActivityIndicatorView for a UITableViewController in the window, not in the table view
问题描述
我在界面设计器中的表格视图中有一个 UIActivityIndicatorView
.我正在尝试使用以下方法将其居中在屏幕中间:
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)
推荐答案
使用自动布局,您可以使用 layoutMarginsGuide
在 UITableView
中获得正确的中心 X、Y 锚点>s 和 UICollectionView
s:
Using auto layout, you can use layoutMarginsGuide
to get the right center X, Y anchor in both UITableView
s and UICollectionView
s:
activityView.translatesAutoresizingMaskIntoConstraints = false
activityView.centerXAnchor.constraint(equalTo: view.layoutMarginsGuide.centerXAnchor).isActive = true
activityView.centerYAnchor.constraint(equalTo: view.layoutMarginsGuide.centerYAnchor).isActive = true
这篇关于在窗口中将 UITableViewController 的 UIActivityIndicatorView 居中,而不是在表视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!