[英]how can I make my table view controller scrollable, so the user can swipe it up from the bottom of the screen?
I am writing a Swift
application, currently I have the storyboard open and I have a UIViewController
with two elements: UIImageView
and TableViewController
, placed one below the other:我正在编写一个Swift
应用程序,目前我打开了故事板,我有一个UIViewController
有两个元素: UIImageView
和TableViewController
,放在另一个下面:
As you may see, the table view controller does not cover the image and is half-visible.如您所见,表视图控制器不覆盖图像并且是半可见的。 I want to apply my constraints so that when user swipes it up - the table view controller covers part of the photo:我想应用我的约束,以便当用户向上滑动时 - 表视图控制器覆盖了照片的一部分:
and then he will be able to scroll the table further down.然后他将能够进一步向下滚动表格。
The table itself is dynamically filled with cells, so sometimes it has 10 cells, and sometimes less.表格本身由单元格动态填充,因此有时它有 10 个单元格,有时更少。
Can you help me and tell me how can I do that so that when user swipes the table view up - first it moves the whole component up and then scrolls the table inside of it?你能帮我告诉我我该怎么做,以便当用户向上滑动表格视图时 - 首先它向上移动整个组件,然后在其中滚动表格?
My inspiration is periscope app, where when you watch the video, the first screen looks like this:我的灵感来自潜望镜应用程序,当您观看视频时,第一个屏幕如下所示:
but when you swipe up the white component - it covers 80% of the screen and user is able to scroll the content that's inside:但是当您向上滑动白色组件时 - 它覆盖了屏幕的 80%,用户可以滚动其中的内容:
This link [ https://medium.com/@dineshk1389/pull-down-table-views-e33d4c85018b#.c9havwadt] might be useful.此链接 [ https://medium.com/@dineshk1389/pull-down-table-views-e33d4c85018b#.c9havwadt]可能有用。
It provides almost the same functionality that you are looking for.它提供了您正在寻找的几乎相同的功能。
So I think you need to do two different things here.所以我认为你需要在这里做两件不同的事情。
The first is to enable scrolling in the tableview, as Rashwan noted above.第一个是在 tableview 中启用滚动,如 Rashwan 上面提到的。 That will handle the case where the number of items is larger than the table, even if it's "scrolled into view".这将处理项目数大于表格的情况,即使它“滚动到视图中”。 However, you may wish to turn this off when you have the table "down".但是,您可能希望在表格“向下”时关闭此功能。 My question here is what scrolling will look like when only a bit of the table is on-screen.我的问题是当屏幕上只有一小部分表格时滚动会是什么样子。 You'll just have to try it你只需要尝试一下
The second part is just to move the table up and down.第二部分只是上下移动桌子。 Add a UISwipeGestureRecognizer
to the view to do this, here is a tutorial.向视图添加UISwipeGestureRecognizer
以执行此操作,这是一个教程。 Don't bother resizing the table or anything, simply change it's Y value and it should all just work.不要费心调整表格或任何东西的大小,只需更改它的 Y 值,它应该都能正常工作。 I do things like this in my apps, where the view is offscreen or hidden and then just move it into the display and off again instead of open/close.我在我的应用程序中做这样的事情,其中视图在屏幕外或隐藏,然后将其移入显示器并再次关闭而不是打开/关闭。
Be sure you always make the various Y values relative to your subview - don't assume absolute values or it will go wonky when you change screen sizes.确保您始终使各种 Y 值相对于您的子视图 - 不要假设绝对值,否则当您更改屏幕尺寸时它会变得不稳定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.