iOS
UIWebView
bouncing effect
mobile development
webview customization

Stop UIWebView from bouncing vertically?

Interview Questions practice on Codemia

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

Browse interview questions

Introduction

To stop a UIWebView from bouncing vertically, you disable bouncing on its underlying UIScrollView. The important caveat is that UIWebView is deprecated, so the same idea is still useful mostly when maintaining older code rather than writing a new iOS web view today.

Core Sections

The direct property to change

UIWebView exposes its internal scroll view through the scrollView property. To disable the elastic vertical bounce effect, set bounces to false.

swift
1import UIKit
2
3class ViewController: UIViewController {
4    @IBOutlet weak var webView: UIWebView!
5
6    override func viewDidLoad() {
7        super.viewDidLoad()
8        webView.scrollView.bounces = false
9    }
10}

That is the most common answer. It disables the bounce effect in both directions unless other scroll settings override the behavior.

If you care only about vertical behavior

Sometimes you want horizontal behavior preserved but vertical bounce removed. In practice, bounces = false is usually enough for static layouts, but scroll behavior also depends on alwaysBounceVertical and content size.

swift
webView.scrollView.alwaysBounceVertical = false
webView.scrollView.bounces = false

If the content is smaller than the view, this prevents the user from dragging the web content into empty overscroll space.

When the bounce seems to come back

If your code sets these properties too early and the web view or its content resets scroll behavior later, move the configuration to a point after the web view is created and retained. In many maintenance codebases, viewDidLoad is enough, but if the web view is recreated dynamically you may need to reapply the scroll settings.

Modern equivalent in WKWebView

New code should not use UIWebView. The modern equivalent is WKWebView, and the same scroll-view idea still applies.

swift
1import WebKit
2
3let webView = WKWebView(frame: .zero)
4webView.scrollView.bounces = false

If you are touching legacy UIWebView code anyway, it is worth checking whether the screen should be migrated to WKWebView rather than patched repeatedly.

Know what you are changing

Disabling bounce affects user feel, not just visuals. iOS users expect a certain amount of elasticity in scrollable interfaces. For static embedded content, removing it often makes sense. For long documents or normal browsing surfaces, it can make the UI feel less native.

That is why the real question is not only "how do I disable it" but also "should this particular screen behave like a document, a browser, or a fixed embedded panel?"

If the content is very short and still appears draggable, the issue is often not just bounce but the scroll view's willingness to allow vertical elasticity when the content size is smaller than the frame. Disabling both bounces and alwaysBounceVertical is the most explicit way to shut that behavior off in legacy screens.

Common Pitfalls

  • Setting properties on the wrong object instead of on webView.scrollView.
  • Assuming the fix is UIWebView-specific when the real behavior comes from the underlying scroll view.
  • Forgetting that UIWebView is deprecated and carrying the same design into new code without considering WKWebView.
  • Disabling bounce everywhere even on screens where native web-style scrolling is the better user experience.
  • Confusing bounce behavior with other scrolling issues such as content inset or zoom configuration.

Summary

  • To stop vertical bounce in UIWebView, configure the embedded UIScrollView.
  • The usual fix is webView.scrollView.bounces = false.
  • 'alwaysBounceVertical can also matter depending on the layout.'
  • The same general approach applies to WKWebView, which is the modern replacement.
  • Disable bounce intentionally, because it changes the feel of the interface, not just one visual effect.

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.