ole / OLEContainerScrollView

A UIScrollView subclass that intelligently handles multiple child scroll views and does not interfere with UIKitʼs cell reuse functionality.
http://oleb.net/blog/2014/05/scrollviews-inside-scrollviews/
MIT License
587 stars 67 forks source link

Load views from nib incorrect resize #9

Closed stefanocdn closed 9 years ago

stefanocdn commented 9 years ago

Views loaded from nib and added to the contentView are resized incorrectly (much bigger), is there a reason for that? I canno't find why

ole commented 9 years ago

I don’t recall if I ever tested this but I am not aware of anything in the code why that should happen.

stefanocdn commented 9 years ago

Really can't get it to work with nib files including subviews constrained with autolayout. Views where constraints are added programmatically work perfectly. If you have any idea ..?

macdrevx commented 9 years ago

@jillhc and I just ran into a similar issue. Ultimately, what fixed it for us was making sure the views we added to the content view had translatesAutoresizingMaskIntoConstraints = YES and autoresizingMask = UIViewAutoresizingNone.

This prevented the subviews from resizing if they were added to the content view prior to the content view's size being adjusted in -[OLEContainerScrollView layoutSubviews].

We only had this problem on devices with 480 pt-tall screens running iOS 7. The 568 pt-tall screens did not encounter the issue because the scroll view started out at the correct height when unarchived from the xib. On iOS 8, our particular usage ended up triggering layout that set the content view's height appropriately prior to when we added subviews. I'm not sure that this is guaranteed in the general case though—we may have just been "lucky".

@ole We think it would make sense for OLEContainerScrollView to ensure that all subviews added to the content view are set appropriately in this regard. Thoughts?

ole commented 9 years ago

@macdrevx Sorry for the late reply. I pushed a fix which works in my tests, although I chose to set translatesAutoresizingMaskIntoConstraints = NO because that makes more sense in my opinion. The container scroll view does not use autolayout internally so the subviews' autoresizing masks should really not be translated into layout constraints. Anyway, I hope this works for you. Thanks for the research.

macdrevx commented 9 years ago

@ole We tried translatesAutoresizingMaskIntoConstraints = NO initially as well, but we ran into issues with infinite recursion (on 8.2)/infinite layout loop (on 7.1) with something related to layout. Do you have any insight into what might cause that to happen?