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

Allow subview layering to be changed #2

Closed joe-trellick closed 10 years ago

joe-trellick commented 10 years ago

I wanted to change the layering of the subviews so that the second subview was behind the first subview (in my case, I have a UI element in the first subview that deliberately oversteps bounds for effect). However, simply sending the second subview to the back of contentView changed the iteration order during the layout process, causing the subviews to be visually reordered.

This change uses a mutable array to track the subview addition order distinctly from the layering order, and allows bringSubviewToFront: and sendSubviewToBack: to work as callers would expect.

ole commented 10 years ago

@joehughes I do see the need for this, but I am not sure your pull request is the way to go here. I definitely don't want to run into a situation where we slowly add a large part of the UIView public interface to this class. Perhaps it would be better to expose the contentView as a public readonly property so that users of the class could access the subviews that way?

joe-trellick commented 10 years ago

Fair enough; I was considering that approach, but I was debating whether exposing that implementation detail was as elegant as using the existing UIView API. (Because it might create a temptation to add/remove views from the contentView without the OLEContainerScrollView knowing.) However, if you're generally happy with the main approach of keeping the vertical ordering in an array that's distinct from the subview (layering) ordering, I'll change this PR to expose the contentView you suggest.

ole commented 10 years ago

@joehughes I apologize (again) for not replying earlier. Iʼm really sorry that I am managing this so badly. But I do have a plan now that I think should work well (and also be future-proof):

What do you think? Will you make the contentView property public and remove the methods you added? Then I will merge the pull request and do the rest.

joe-trellick commented 10 years ago

Thanks @ole, I took a crack at the design you suggested (see the updated pull request). Now the exposed interface is just adding and removing views from the contentView directly. It's a little bit ugly internally because I put the UIView subclass in the same file to give it "protected" access to the now-renamed didAddSubviewToContainer: and willRemoveSubviewFromContainer: methods. If you'd prefer to have them in separate files with those methods exposed by a separate category header, let me know (I'm finding this an interesting exercise).

ole commented 10 years ago

Thanks @joehughes.