以小于帧大小的增量分页UIScrollView [英] Paging UIScrollView in increments smaller than frame size

查看:73
本文介绍了以小于帧大小的增量分页UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滚动视图,它是屏幕的宽度,但只有大约70像素高。它包含许多50 x 50图标(周围有空格),我希望用户可以选择。但我总是希望滚动视图以分页的方式运行,始终在正确的中心以图标停止。

I have a scroll view that is the width of the screen but only about 70 pixels high. It contains many 50 x 50 icons (with space around them) that I want the user to be able to choose from. But I always want the scroll view to behave in a paged manner, always stopping with an icon in the exact center.

如果图标是屏幕的宽度,这不会有问题,因为UIScrollView的分页会处理它。但是因为我的小图标远小于内容大小,所以它不起作用。

If the icons were the width of the screen this wouldn't be a problem because the UIScrollView's paging would take care of it. But because my little icons are much less than the content size, it doesn't work.

我之前在应用程序调用AllRecipes中看到过这种行为。我只是不知道该怎么做。

I've seen this behavior before in an app call AllRecipes. I just don't know how to do it.

关于如何按照每个图标大小进行分页工作的任何想法?

Any ideas about how to get paging on a per-icon sized basis to work?

推荐答案

尝试使您的滚动视图小于屏幕大小(宽度方式),但取消选中IB中的剪辑子视图复选框。然后,在其上覆盖透明的userInteractionEnabled = NO视图(全宽),覆盖hitTest:withEvent:以返回滚动视图。这应该会给你你想要的东西。有关详细信息,请参见此答案

Try making your scrollview less than the size of the screen (width-wise), but uncheck the "Clip Subviews" checkbox in IB. Then, overlay a transparent, userInteractionEnabled = NO view on top of it (at full width), which overrides hitTest:withEvent: to return your scroll view. That should give you what you're looking for. See this answer for more details.

这篇关于以小于帧大小的增量分页UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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