Paging UIScrollView with peeking neighbor pages(使用窥视相邻页面分页 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用窥视相邻页面分页 UIScrollView
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01