以小于帧大小的增量分页 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.
如何让按图标大小的分页起作用?
How do I 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.
相关文章