简体   繁体   English

如何使我的表视图控制器可滚动,以便用户可以从屏幕底部向上滑动它?

[英]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有两个元素: UIImageViewTableViewController ,放在另一个下面:

在此处输入图片说明

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.

相关问题 如果视图控制器不可滚动,我可以执行“拉动刷新”操作吗? - can I make 'pull to refresh' action if my view controller is not scrollable? 如何使动画视图与所有设备上的屏幕底部保持一致的距离? - How can I make an animated view be a consistent distance from the bottom of the screen on all devices? 如何在iOS表格视图的底部制作固定单元格? - How can I make the fixed cell at the bottom of the table view in iOS? 当视图控制器仍在视图控制器堆栈中但不可见时,如何防止MKMapView占用太多内存? - How can I prevent MKMapView from eating up so much memory when the view controller is still in the view controllers stack, but is not visible? 如何制作用户可以滑动以切换视图的UI - How do I make this kind of UI that user can swipe to switch view 在表格视图 controller 添加容器视图时,如何将其移动到最底部? (迅速) - In a table view controller when adding a container view, how can I move it to the very bottom? (Swift) 如何使视图的一部分可滚动? - How can I make one part of view scrollable? 如何将数据从弹出视图控制器发送到主视图控制器。 传递一个字符串,以便我可以将其作为主视图中的标签文本 - how to send data from popover view controller to main view controller. Pass a string so that i can make that as the label text in the main view 如何在不使其成为我的根视图控制器的情况下从视图控制器转到拆分视图控制器 - How can I segue from view controller to Split view Controller Without making it my root View Controller 如何使视图控制器可滚动? - How to make a view controller scrollable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM