Jason Hocker
Jason Hocker

Reputation: 7067

UICollectionView. Only allow either vertical or horizontal scrolling at a time

We build a calendar view using a UICollectionView. We'd like to scroll vertically to change the time of day we view, or scroll horizontally to change the week.

Right now dragging the calendar affects both these. We'd like to lock it in more so that whichever scroll direction has more velocity is the only way we scroll.

So we do not want to disable one direction. We just only want to allow one at a time.

Is there a scroll view property or something that supports this?

Upvotes: 1

Views: 2087

Answers (1)

Rashwan L
Rashwan L

Reputation: 38833

You can set the isDirectionalLockEnabled to true on your scrollView:

If this property is true and the user begins dragging in one general direction (horizontally or vertically), the scroll view disables scrolling in the other direction.

Upvotes: 7

Related Questions