Stop UIWebView from bouncing vertically?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
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.
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.
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.
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
UIWebViewis deprecated and carrying the same design into new code without consideringWKWebView. - 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 embeddedUIScrollView. - The usual fix is
webView.scrollView.bounces = false. - '
alwaysBounceVerticalcan 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
- Stopping an Android app from console
- Store a closure as a variable in Swift
- Storing authentication tokens on iOS - NSUserDefaults vs Keychain?
- Storyboard - refer to ViewController in AppDelegate
- Storyboard doesn't contain a view controller with identifier
- Storyboard Segue From View Controller to Itself
- Storyboard warning prototype table cells must have reuse identifiers
- Streaming video from Android camera to server
.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.