UIScrollView
ScrollView issue
iOS development
app troubleshooting
mobile UI design

UIScrollView not scrolling

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

When a UIScrollView refuses to scroll, the problem is usually not mysterious. In most cases, the scroll view simply has no larger content area to scroll, or Auto Layout never produced the correct content size.

The fix depends on how the scroll view is built. If you lay it out manually, check contentSize. If you use Auto Layout, check the constraints attached to contentLayoutGuide and frameLayoutGuide.

The First Rule: The Content Must Be Bigger Than the Frame

A scroll view only scrolls when its content area is larger than its visible frame. If the content is the same height and width as the viewport, there is nothing to scroll.

In manual layout code, that means setting contentSize correctly:

swift
1let scrollView = UIScrollView(frame: view.bounds)
2scrollView.backgroundColor = .systemBackground
3
4let contentView = UIView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 1400))
5contentView.backgroundColor = .systemGray6
6
7scrollView.addSubview(contentView)
8scrollView.contentSize = contentView.bounds.size
9view.addSubview(scrollView)

If contentSize.height is not greater than the scroll view height, vertical scrolling will not happen.

Auto Layout Needs Complete Constraints

In modern iOS code, the most common cause is incomplete Auto Layout setup. The recommended pattern is:

  • pin the scroll view itself into the parent view
  • pin the content view to the scroll view's contentLayoutGuide
  • constrain the content view width to the scroll view's frameLayoutGuide for vertical scrolling

Example:

swift
1let scrollView = UIScrollView()
2let contentView = UIStackView()
3
4scrollView.translatesAutoresizingMaskIntoConstraints = false
5contentView.translatesAutoresizingMaskIntoConstraints = false
6contentView.axis = .vertical
7contentView.spacing = 16
8
9view.addSubview(scrollView)
10scrollView.addSubview(contentView)
11
12NSLayoutConstraint.activate([
13    scrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
14    scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
15    scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
16    scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
17
18    contentView.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor),
19    contentView.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor),
20    contentView.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor),
21    contentView.bottomAnchor.constraint(equalTo: scrollView.contentLayoutGuide.bottomAnchor),
22
23    contentView.widthAnchor.constraint(equalTo: scrollView.frameLayoutGuide.widthAnchor)
24])

That bottom constraint is especially important. Without it, Auto Layout often cannot infer the full scrollable height.

Common Real Causes

If a scroll view is not scrolling, check these in order:

  • the content is not actually taller or wider than the viewport
  • the bottom or trailing content constraint is missing
  • the content view width is not tied correctly, so the layout is ambiguous
  • another gesture recognizer or parent view is intercepting touches
  • the scroll view itself has zero or incorrect frame size

Many "scrolling bugs" are really layout bugs.

Nested Scroll Views and Stack Views

Problems get more common when you place a stack view inside a scroll view or nest scrollable controls. The stack view itself does not make scrolling happen. It still needs complete constraints so the scroll view can derive the full content size.

Likewise, if you embed a table view or collection view inside another scroll view, gesture handling and content sizing become more complicated. Often the cleaner solution is to use one main scrolling container instead of stacking several scrollable views.

Common Pitfalls

  • Forgetting that contentSize must exceed the visible frame for scrolling to occur.
  • Missing the bottom constraint between content and contentLayoutGuide.
  • Pinning content directly to the scroll view frame instead of using the layout guides correctly.
  • Assuming a UIStackView inside the scroll view automatically creates scrollable height.
  • Debugging gestures first when the real problem is that the content simply is not larger than the viewport.

Summary

  • A UIScrollView scrolls only when its content area is larger than its frame.
  • Manual layout requires a correct contentSize.
  • Auto Layout requires complete constraints to contentLayoutGuide and usually a width constraint to frameLayoutGuide.
  • Missing bottom constraints are a very common cause.
  • When a scroll view does not scroll, verify layout and content size before chasing gesture issues.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.