問題描述
我有一個 UIScrollView,我希望它能夠雙向滾動(目前可以),但一次只能滾動一個.因此,例如,如果您開始水平滾動它,它根本不會垂直移動,直到您松開并開始垂直移動它.我該怎么做呢?
I have a UIScrollView and I want it to be able to scroll in both directions (it currently does) but only one at a time. So, for instance, if you start scrolling it horizontally, it won't move vertically at all until you let go and start moving it vertically. How could I go about doing this?
推薦答案
將 directionalLockEnabled
屬性設置為 YES.來自 Apple 文檔:
Set the directionalLockEnabled
property to YES. From the Apple docs:
如果此屬性為 NO,則允許在水平和垂直方向上滾動.如果此屬性為 YES 并且用戶開始沿一個大致方向(水平或垂直)拖動,則滾動視圖將禁用在另一個方向上的滾動.如果拖動方向是對角線,則滾動不會被鎖定,用戶可以向任意方向拖動,直到拖動完成.默認值為否
If this property is NO, scrolling is permitted in both horizontal and vertical directions. If this property is YES and the user begins dragging in one general direction (horizontally or vertically), the scroll view disables scrolling in the other direction. If the drag direction is diagonal, then scrolling will not be locked and the user can drag in any direction until the drag completes. The default value is NO
這篇關于UIScrollView 一次只向一個方向滾動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!