UIScrollView paging horizontally, scrolling vertically?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If you want horizontal paging but free vertical scrolling, a single UIScrollView is usually the wrong abstraction. isPagingEnabled pages in the scroll view's scrolling dimensions, so the practical solution is normally a horizontally paged container where each page contains its own vertically scrollable content.
Why One Scroll View Usually Fights You
A UIScrollView with isPagingEnabled = true snaps based on its bounds. If the same scroll view is also vertically scrollable, you do not get a clean "horizontal paging plus ordinary vertical content scroll" experience automatically. The gesture handling and content snapping are not designed around that mixed interaction model.
This is why people usually build the UI as:
- an outer horizontal pager
- one inner vertical scroll view per page
That design matches the user interaction more naturally.
A Practical Structure
The outer scroll view pages horizontally across full-screen or full-width pages. Each page is a regular UIView containing a vertically scrolling view, often another UIScrollView, UITableView, or UICollectionView.
In this setup, the outer view handles horizontal paging and each inner scroll view handles vertical movement inside a page.
Why Nested Scrolling Works Better
Separating the axes gives each scroll view a clear responsibility:
- outer scroll view: horizontal page changes
- inner scroll view: vertical content movement within one page
That is much easier to maintain than trying to coerce one scroll view into two interaction styles that partially conflict.
In real apps, the inner scrollable view is often a table view or collection view rather than a raw scroll view.
Collection View Is Often Better Than Manual Paging
If the UI is really a series of horizontally swipeable pages, a horizontally paging UICollectionView is usually cleaner than manually managing page frames.
For example:
Then each cell can host its own vertical content view. This approach scales better when the number of pages is dynamic.
Gesture Conflicts Still Need Attention
Nested scroll views can still fight over gestures if the content and layout are not designed carefully. Keep these rules in mind:
- only the outer container should own horizontal paging
- inner views should primarily scroll vertically
- avoid accidental horizontal content size inside inner scroll views
If an inner table or collection view can also scroll sideways, gesture competition becomes more complicated.
This is one reason UICollectionView with well-defined page cells often feels more predictable than hand-built nested scroll views.
Common Pitfalls
- Expecting one
UIScrollViewwithisPagingEnabledto behave like a horizontal pager and an ordinary vertical scroller at the same time. - Forgetting to set the outer content width to the total page width.
- Giving inner pages unintended horizontal scrollable content.
- Building manual nested scroll views when a horizontally paging collection view would be simpler.
- Debugging gesture behavior without first separating which scroll view should own which axis.
Summary
- A single scroll view is usually not the best solution for horizontal paging plus free vertical scrolling.
- The common design is an outer horizontal pager with one inner vertical scroll view per page.
- '
UICollectionViewis often the cleanest modern container for horizontally paged pages.' - Keep horizontal ownership in the outer container and vertical ownership in the inner content view.
- Clear axis separation makes the interaction much more predictable.
Related reading
- UIScrollView pauses NSTimer until scrolling finishes
- UIScrollView scroll to bottom programmatically
- UIScrollView Scrollable Content Size Ambiguity
- UIScrollView Scrollable Content Size Ambiguity
- UISearchBar increases navigation bar height in iOS 11
- UISegmentedControl below UINavigationbar in iOS 7
- UISegmentedControl change number of segments programmatically
- UISlider with increments of 5
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.