viedev
viedev

Reputation: 1527

UIScrollView jumps when content has almost the same size as screen

I have an UIScrollView that "jumps" to the end of the content on touch when the content has almost the same size as the screen. This does not happen when the content is significantly smaller or larger (see video).

I assume this has something to do with the safe area as this problem does not appear when the ScrollView is smaller than the safe area.

iPhone 13 Pro Max / Screen width: 926pt / Safe Area width: 838pt

  1. Content Width: 850pt -> Jumping on touch ❌
  2. Content Width: 1000pt -> Normal scrolling ✅
  3. Content Width: 600pt -> No scrolling ✅

UIScrollView

UIScrollView Setup

View -> ScrollView (white) -> ContentView (grey) -> BlueView (blue)

I got a ScrollView that is the same size as the screen (leading, trailing, top, bottom constraints to Superview = 0). Inside is a ContentView (leading, trailing, top, bottom constraints to ScrollView = 0). It also has constraints to be the equal with and height of the highest level view of the ViewController (with a priority of 250). This ContentView wraps around the BlueView which defines its size. It's basically setup as described here: https://medium.com/@pradeep_chauhan/how-to-configure-a-uiscrollview-with-auto-layout-in-interface-builder-218dcb4022d7

As I wrote before, I assume this could have something to do with the safe area and me having some incorrectly setup contraints for the Scroll View, but I can't figure out where I got it wrong. Thanks!

Constraints

Upvotes: 1

Views: 580

Answers (2)

Abhi_Gajjar
Abhi_Gajjar

Reputation: 49

Solution 1:Please Off Scrollview's Bounce On Scroll Solution 2:Take A Parent View Behind

take parent view means firstOfAll Take ViewController > Take A View On It > Then Take ScrollView (Give Equal Width To View)

Upvotes: 0

Rakesh Patel
Rakesh Patel

Reputation: 1701

Please don't give a fixed width of contentView & blueView. Just give a leading & trailing constraint of scrollView in respect to superview. Make scrollView Horizontally centred. Try with above changes. Hope it will work.

Upvotes: 0

Related Questions