使用窥视邻居页面分页UIScrollView [英] Paging UIScrollView with peeking neighbor pages

查看:147
本文介绍了使用窥视邻居页面分页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.

那他们是怎么做到的?

推荐答案

您需要在滚动视图后面添加一个视图,该视图覆盖您的页面可见的整个区域。该视图应该实现-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:

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆