简体   繁体   English

滚动时如何使 UITableView 从下到上显示?

[英]How to make UITableView appear from bottom to top when scroll?

I'm looking just for general scenario.The idea is when app launches user can see only first cell of UITableView at the bottom of UIViewController.我只是在寻找一般情况。这个想法是当应用程序启动时,用户只能看到 UIViewController 底部的 UITableView 的第一个单元格。 When user scrolls up full table appears and when scrolls down only first cell is displayed again.当用户向上滚动整个表格时,向下滚动时只再次显示第一个单元格。 Something similar like keyboard in Facebook messenger app, but with tableView.类似于 Facebook Messenger 应用程序中的键盘,但带有 tableView。 For now I added tableView as subview to scrollView, but problem is tableView appears from top to bottom, and I'm looking for solution how to make this work upside down.. So, tableView have to appear from bottom to top of UIViewController.现在我将 tableView 作为子视图添加到 scrollView,但问题是 tableView 从上到下出现,我正在寻找解决方案如何使这个工作颠倒..所以,tableView 必须从 UIViewController 的底部到顶部出现。

My idea would be:我的想法是:

  • Give your UITableView the desired frame at viewDiDLoad (probably the height of 1 cell, at the bottom of your UIView )viewDiDLoad您的UITableView所需的框架(可能是UIView底部的 1 个单元格的高度)
  • Let your UIViewController implement UIScrollViewDelegate让你的UIViewController实现UIScrollViewDelegate
  • At - (void)scrollViewDidScroll:(UIScrollView *)scrollView of UIScrollViewDelegate check which element is scrolling (if its your UITableView ) and also check which direction user is scrolling- (void)scrollViewDidScroll:(UIScrollView *)scrollView of UIScrollViewDelegate检查哪个元素正在滚动(如果它是你的UITableView )并检查用户滚动的方向
  • Change the frame of the UITableView as you wish, you will also have to come up with some logic to block further changing of the UITableView 's frame (a BOOL would do good here I guess)根据需要更改UITableView的框架,您还必须想出一些逻辑来阻止进一步更改UITableView的框架(我猜在这里 BOOL 会很好)

Not sure I understand your correctly but, maybe, this will be helpful不确定我是否理解正确,但也许这会有所帮助

I believe you can try to add zero cell (or first section header view of your UITableView ) with transparent background.我相信您可以尝试添加具有透明背景的零单元格(或UITableView第一部分标题视图)。 So that your first cell will be placed on the bottom of screen and UITableView height will be equal to screen height.这样您的第一个单元格将被放置在屏幕底部并且UITableView高度将等于屏幕高度。

In this case, you will have only one scrolling view ( UITableView , in particularly).在这种情况下,您将只有一个滚动视图(尤其是UITableView )。 Following method can be used to perform expandable animation and scroll table to top to hide zero cell when user taps on first cell:当用户点击第一个单元格时,以下方法可用于执行可扩展动画并将表格滚动到顶部以隐藏零单元格:

[UITableView scrollRectToVisible:animated:]

After that you can leave UITableView as it is and "constrict" your table whenever you need in the same way as it was expanded before.之后,您可以保留UITableView原样,并在需要时以与之前扩展相同的方式“压缩”您的表格。

I understand what you want to do.我明白你想做什么。 In general, UITableView shows cells from top to bottom.一般来说,UITableView 从上到下显示单元格。

You can add transform in tableview:您可以在 tableview 中添加转换:

tableView.transform = CGAffineTransform(scaleX: 1, y: -1)

Then your tableview will show the cells from bottom to top and you can scroll tableview from bottom to top.然后您的 tableview 将从下到上显示单元格,您可以从下到上滚动 tableview。 But cells will be transformed as tableview, so you have to add same transform to cells also.但是单元格将转换为 tableview,因此您还必须向单元格添加相同的转换。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell")

    **cell.transform = tableView.transform**

    return cell
}

All done.全部完成。 Hope to helpful!希望有帮助!

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

相关问题 如何检测UITableView何时滚动到最底部/顶部? - How can I detect when a UITableView has been scroll past the very bottom/top? 如何以编程方式使UITableView的第一部分显示在距顶部边框一定距离的地方? - How do I make the first section of UITableView appear at a certain distance from the top border programmatically? 从下到上滚动 - Scroll from bottom to top 将顶视图添加到UITableview并将其滚动到导航栏的底部 - Add a top view to UITableview and scroll it to bottom of navigationbar 在顶部添加单元格时,使UITableView保持滚动位置 - Make UITableView keep scroll position when adding cells at top 如何使按下状态栏滚动到任何UITableView的顶部? - How to make pressing the status bar scroll to the top of any UITableView? 如何知道UITableView何时在iPhone中滚动到底部 - How to know when UITableView did scroll to bottom in iPhone 当键盘隐藏屏幕的下半部分时如何滚动 UITableView - How to scroll UITableView When Keyboard hides the bottom half section of the screen 使UITableView的最后一行显示在顶部 - Make the last row in UITableView appear at top 如何使导航栏始终显示在顶部,而不滚动内容IOS 8 - how to make navigation bar always appear on top and not scroll with content IOS 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM