1

I'm trying to use auto layout with a {320,116} UIScrollView, with a content view of {960, 116}. I have made it so that the scroll view expands or collapses in height when the user scrolls up or down, and horizontal scrolling is paged (so, a total of three pages).

The problem is that when the view expands or collapses--I do this by changing top space to Top Layout Guide, the content offset value is reset to CGPointZero, so whenever the view is on page 2 or 3, its is reset to 1 against the user's will as it expands or collapses.

The leading space of UIScrollView to superview is equal to 0.

funct7
  • 3,407
  • 2
  • 27
  • 33
  • How can you scroll up and down if the `contentView` has the same height of the scroll view? – DeFrenZ Sep 29 '14 at 23:26
  • I added another gesture recognizer that responds to touch movement in the y axis using `translationInView`. The triggered method shortens the constraint constant, thereby expanding the height of the scroll view. Scrolling down does the opposite. The only problem is, when the constant of the top space constraint is shortened, `contentOffset` of `UIScrollView` is reset to CGPointZero, meaning, if the `contentOffset` was {320, 0}, page 2, it goes back to page 1 as it expands/collapses. – funct7 Sep 30 '14 at 00:22
  • Then why not make a single paged horizontal `UIScrollView` with 3 vertical unpaged `UIScrollView`s inside it? Seems a more reasonable approach if your purpose is to make 3 separate "pages". – DeFrenZ Sep 30 '14 at 09:04

1 Answers1

0

Two things I found out.

1) In iOS7, if you don't specifically set the space and dimension constraints of the content view (the child view of UIScrollView) and modify a constraint constant, contentOffset is set to CGPointZero.

2) This same problem doesn't happen in iOS8, meaning even if you don't have constraints set for the content view, contentOffset won't be reset to CGPointZero.

funct7
  • 3,407
  • 2
  • 27
  • 33