I have a library that programmatically constructs a UIView that exhibits my custom behavior. This library could be dropped into many different applications at different places in the view hierarchy. Under certain circumstances the view needs to "expand" to fill the screen real estate. I am currently doing this by having my code walk the view hierarchy until I find a view with no parent, constructing a new view and inserting it as a subview of that found view, and then performing an animated transition between the two. Exiting that new view is merely a matter of hiding it, which restores the previous state.
I have two questions.
- Is there a better way to do this? (In particular, I don't really like traversing the view hierarchy like that.)
- What bad things can happen with this approach? One thing that could go wrong, for example, is that the view that previously was on display doesn't know that this has happened and therefore might behave erratically. (This could be solved by inventing a delegation protocol for this behavior or using an existing protocol that I am currently unaware of.)
The goal here, obviously, is for the containing application/view/controller to be required to do as little as possible, short of creating a rectangle and constructing my view's controller.