简体   繁体   English

将浮动视图(即静态和固定)添加到UITableViewController

[英]Add floating view (i.e. static and fixed) to UITableViewController

I'm trying to add a custom subview to a UITableViewController that doesn't move when the user scrolls. 我正在尝试向用户滚动时不移动的UITableViewController添加自定义子视图。

Is it possible to add such a view? 是否可以添加这样的视图?

I'm using a UITableViewController . 我正在使用UITableViewController I would switch to a UIViewController and add a UITableView , but the code relies on the UITableViewController's refreshControl . 我会切换到UIViewController并添加一个UITableView ,但代码依赖于UITableViewController的refreshControl Adding a container view and having two controllers seems a bit much for such a simple task! 添加一个容器视图并拥有两个控制器对于这么简单的任务来说似乎有点多了!

I've also tried adding the content to the UINavigationController view, but unfortunately it doesn't animate smoothly when the view controller appears and disappears. 我也尝试将内容添加到UINavigationController视图中,但不幸的是,当视图控制器出现并消失时,它没有平滑的动画。

Is there any way to add a fixed subview to a UITableView ? 有没有办法将固定的子视图添加到UITableView

Edit: 编辑:

Adding a container view and having two controllers (with an embed segue) is difficult for this project, since I'm updating an older code base and there is a lot of legacy code that depends on the main controller being a UITableViewController . 添加容器视图并具有两个控制器(带有嵌入segue)对于这个项目来说很难,因为我正在更新旧的代码库,并且有很多遗留代码依赖于主控制器是UITableViewController Is there any way to achieve this without an embed segue / two view controllers? 有没有任何方法可以实现这个没有嵌入segue /两个视图控制器?

Unfortunately creating a container view for a UITableViewController inside of a UIViewController isn't feasible in this case. 不幸的是,在这种情况下,为UIViewController内部的UITableViewController创建容器视图是不可行的。 That is a great solution if you're early enough in development to arrange things properly . 如果您在开发过程中尽早安排正确的事情,这是一个很好的解决方案

The best solution I've found, is to transform the floating view's y position on scrollViewDidScroll as per this answer : 我发现的最佳解决方案是根据以下答案scrollViewDidScroll上转换浮动视图的y位置:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.header.transform = CGAffineTransformMakeTranslation(0, self.tableView.contentOffset.y);
}

I have seen other answers which modify the floating view's frame, but I think transforming is probably more appropriate. 我已经看到了修改浮动视图框架的其他答案,但我认为转换可能更合适。

As an interesting aside, I was able to create a floating view that 'dismisses' when the user scrolls down, but 'floats' when the user pulls to refresh by checking the table view offset before applying the transform. 有趣的是,我能够创建一个浮动视图,当用户向下滚动时“解散”,但是当用户通过在应用转换之前检查表视图偏移来拉动刷新时“浮动”。

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

相关问题 将可点击和固定的子视图添加到UITableViewController? - Add clickable and fixed subview to UITableViewController? 将UITableViewController添加到其他视图 - Add UITableViewController to other View UITableViewController 之外的静态表格视图 - Static table view outside UITableViewController 如何在UITableViewController的静态单元格中添加UIView? - How can I add UIView in a static cell in UITableViewController? 应该为UITableViewController中的静态UITableView固定第一个UITableViewCell - First UITableViewCell should be fixed for static UITableView in UITableViewController 如何以编程方式向我的UITableViewController添加活动指示器视图? - How do I add an activity indicator view to my UITableViewController programmatically? 在 tableview 上添加视图(UITableViewController) - Add view over tableview (UITableViewController) 以编程方式将UITableViewController添加到当前视图 - Add UITableViewController to Current View Programmatically 在UITableViewController中的tableview之后添加视图 - Add view behind tableview in UITableViewController 向其子视图添加约束时无法保持固定大小的 collectionview 单元格,即 UILabel - Unable to keep a fixed size of collectionview cell when adding constraint to it's subview i.e. a UILabel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM