简体   繁体   English

UIView在UITableViewController的中心

[英]UIView on the center of UITableViewController

如何将UIView( loadingView )从UITableViewController加载到屏幕中心,无论滚动的位置如何?

You can add the view to the superview of the tableview, like this: 您可以将视图添加到tableview的superview,如下所示:

loadingView.center = self.tableView.center;
[self.tableView.superview addSubview:loadingView];

and remove it (removeFromSuperview) when you are done with it. 完成后删除它(removeFromSuperview)。 It will appear on top of the table, centered to the table, but won't scroll with the table. 它将显示在表格的顶部,以表格为中心,但不会随表格滚动。

Shift your code into a UIViewController subclass instead of a UITableViewController subclass. 将代码转换为UIViewController子类而不是UITableViewController子类。 That way, you can add your loading view to an actual view instead of a table. 这样,您可以将加载视图添加到实际视图而不是表。 Then, conform to UITableViewDelegate and UITableViewDataSource in your .h, set the delegates and add the table as a subview of the main view. 然后,在.h中符合UITableViewDelegateUITableViewDataSource ,设置委托并将表添加为主视图的子视图。 You won't even miss that ol' UITableViewController. 你甚至不会错过那个'UITableViewController'。

Instead of adding the loadingView to the table's subView. 而不是将loadView添加到表的subView。 Do this instead: 改为:

    [[UIApplication sharedApplication].keyWindow addSubview:loadingView];

This solves having to shift code to a UIViewController 这解决了必须将代码转移到UIViewController的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM