0

UIScrollView doesn't work correctly with Auto Layouts. I have read a lot about how to create working scroll view in code but in my case it's created in Interface Builder.

The simplest example - we auto-scroll active text field to visible area when keyboard is shown. Sample from Apple doesn't work, as well as many examples in internet (contentInset conflicts with auto-layout constraints).

So is there a working approach for this case: UIScrollView created in Interface Builder with enabled Auto Layouts changes contentInset and contentOffset.

brigadir
  • 6,874
  • 6
  • 46
  • 81
  • http://stackoverflow.com/questions/19311045/uiscrollview-animation-of-height-and-contentoffset-jumps-content-from-bottom/19344402#19344402 - is it what you're looking for? It doesn't have a text field in the scroll view, but I think it'll be similar if it had. – Arek Holko Oct 29 '13 at 11:11
  • I'm discovering GitHub sample from answer in your link. In my case `contentSize` of scroll view is zero (in spite of correct value in collection view from that sample). – brigadir Oct 29 '13 at 13:10
  • Do you have any warnings in the Interface Builder? My guess is that a scroll view can't get its `contentSize`, because subviews aren't connected to the top and the bottom of the scroll view. – Arek Holko Oct 29 '13 at 14:05
  • No warnings. From my experiments, table and collection views scroll right. The issue with `contentSize` is actual only for `UIScrollView`. – brigadir Oct 29 '13 at 14:11
  • https://developer.apple.com/library/ios/technotes/tn2154/_index.html maybe this document will help you. I use the `Pure Auto Layout Approach` in the app I'm working on right now and don't have any problems with it. – Arek Holko Oct 29 '13 at 14:14
  • I already read it. There scroll view is created from code. Did you use "Pure layout approach" for scroll view from Interface Builder? – brigadir Oct 29 '13 at 14:18
  • Yes. Can you post a sample project showing the part that doesn't work as expected? – Arek Holko Oct 29 '13 at 14:24
  • Arkadiusz, I already switched to UITableView - in that case content offset is correct. Sorry, but I have no free time to test it on sample project. Thanks for your attention and link to GitHub project with working collection view. – brigadir Oct 30 '13 at 13:30

0 Answers0