简体   繁体   English

在UIScrollView中嵌入UITableView / UICollectionView

[英]Embed UITableView/UICollectionView in UIScrollView

I am trying to build a two-dimensional navigation in an app, similar to what Snapchat has done. 我正在尝试在应用程序中构建二维导航,类似于Snapchat所做的。 See picture below for reference of what I am trying to achieve. 请参阅下面的图片,以获取我要实现的目标的参考。 I tried to do this by putting all views inside of a UIScrollView and then manually creating direction locks to restrict it to never be able to scroll onto the empty, top left, area. 我试图通过将所有视图放入UIScrollView ,然后手动创建方向锁来限制它永远无法滚动到左上角的空白区域来实现此目的。 The idea came from here . 这个主意来自这里 This does the job to some extent, but the UITableView is not cooperating with the UIScrollView very much, and it seems as though they fight for the ownership of touches. 这在某种程度上确实可以完成这项工作,但是UITableViewUIScrollView合作并不多,似乎他们在争取触摸的所有权。 I can only scroll the table view after selecting one of its rows first, and I need to touch outside of the table view in order to scroll back to the right. 我只能先选择其中的一行后才能滚动表格视图,并且需要触摸表格视图之外才能向右滚动。

I know that embedding UITableViews inside UIScrollViews is not recommended by Apple, perhaps even discouraged: 我知道Apple 不推荐UIScrollViews中嵌入UITableViews ,甚至不建议这样做:

Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. 重要说明:您不应在UIScrollView对象中嵌入UIWebView或UITableView对象。 If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled. 如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能会混合在一起并且处理不当。

But I do not see another way to achieve this. 但是我看不到实现这一目标的另一种方法。 I have also tried using two separate UIScrollViews , one for horizontal scrolling and the other one would be embedded in the first one and control all vertical scrolling. 我也尝试过使用两个单独的UIScrollViews ,一个用于水平滚动,另一个将嵌入在第一个中并控制所有垂直滚动。 I had issues setting this up, though, as one of the views would render its subviews rather weird. 不过,我在设置它时遇到了问题,因为其中一种视图会使它的子视图变得很奇怪。

If there only was a way to disable a UIScollView 's horizontal or vertical pan gesture recognizer... I have also tried setting the UIScrollView 's delaysTouchesBegan and canCancelContentTouches to different values, without any luck. 如果只有一种方法可以禁用UIScollView的水平或垂直平移手势识别器...我也尝试过将UIScrollViewdelaysTouchesBegancanCancelContentTouches为不同的值,没有任何运气。

在此处输入图片说明

如果您想要的是Snapchat风格的效果,则应该可以将UIPageViewController用于水平分页,然后将UITableViewUIScrollView用于垂直内容。

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

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