問題描述
我有一個滾動視圖,它是屏幕的寬度,但只有大約 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!