查看 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!