以小于帧大小的增量分页 UIScrollView

Paging UIScrollView in increments smaller than frame size(以小于帧大小的增量分页 UIScrollView)
本文介绍了以小于帧大小的增量分页 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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Resume game cocos2d(恢复游戏 cocos2d)
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)
How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?(如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?)