Center a UIActivityIndicatorView for a UITableViewController in the window, not in the table view

痴心易碎 提交于 2019-12-25 09:09:37

问题


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
    }

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)


回答1:


The solution was to set the activityView frame to the bounds of the view. Setting just the center doesn't work because the y value for the tableView frame is negative.

override func viewWillLayoutSubviews() {
    self.activityView.translatesAutoresizingMaskIntoConstraints = true
    self.activityView.frame = self.view.bounds
}



回答2:


Have you tried:

  self.activityView.center = self.view.window?.center

If not then how about this:

let screenSize = UIScreen.main.bounds
self.activityView.center = CGPoint(x: screenSize.width / 2, y: screenSize.height / 2)

It's a bit longer but handles In-Call Status Bar well.



来源:https://stackoverflow.com/questions/41886374/center-a-uiactivityindicatorview-for-a-uitableviewcontroller-in-the-window-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!