使用窥视相邻页面分页 UIScrollView

Paging UIScrollView with peeking neighbor pages(使用窥视相邻页面分页 UIScrollView)
本文介绍了使用窥视相邻页面分页 UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

查看 iPhone 或 iPad 上的 App Store 应用程序,特别是显示屏幕截图的应用程序详细信息屏幕上的部分.屏幕截图查看器显示您正在查看的屏幕截图,以及下一个和上一个屏幕截图的边缘.我需要实现类似的东西.

Look at the App Store app, on either the iPhone or the iPad, specifically the piece on the screen of app details that shows screenshots. The screenshot viewer shows you the screenshot you're looking at, and the edges of the next and previous one. I need to implement something much like that.

我的做法对穷人来说是公平的:我构建了一个 UIScrollView 并启用了分页并布置了我的内容.我使框架与内容页面的大小相同,但比屏幕小.然后我禁用了 clipToBounds,因此 ScrollView 框架之外的任何内容仍会被绘制.现在我可以看到相邻页面的边缘,但它们在 ScrollView 之外,因此无法接收滚动触摸.App Store 应用可让您触摸该内容的整个宽度,包括相邻页面的窥视边缘.

How I've done it is fair to poor: I built a UIScrollView and enabled paging and laid out my content. I made the frame be the same size as a page of content, but smaller than the screen. Then I disabled clipToBounds, so whatever's outside the frame of the ScrollView still gets drawn. Now I can SEE the edges of the adjacent pages, but they're outside the ScrollView and so can't receive scroll touches. The App Store app lets you touch the whole width of that thing, including the peeking edges of the neighboring pages.

那么他们是怎么做到的呢?

So how'd they do that?

推荐答案

您需要在滚动视图的后面"添加一个视图,该视图覆盖了您的页面可见的整个区域.这个视图应该实现 -hitTest:withEvent:.操作系统将调用此方法来确定将特定触摸事件路由到何处.您需要做的就是返回此支持视图中任何点的滚动视图:

You need to add a view 'behind' the scroll view which covers the entire area where your pages will be visible. This view should implement -hitTest:withEvent:. This method will get called by the OS to determine where to route a particular touch event. All you need to do is return your scroll view for any points within this backing view:

目标-C

- (UIView *) hitTest: (CGPoint) pt withEvent: (UIEvent *) event {
    if (CGRectContainsPoint(self.bounds, pt)) return self.scrollView;
    return [super hitTest: pt withEvent: event];
}

斯威夫特 4.0

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    return self.bounds.contains(point) ? self.scrollView : super.hitTest(point, with: event)
}

这篇关于使用窥视相邻页面分页 UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
How to Cancel Scrolling in UIScrollView(如何在 UIScrollView 中取消滚动)