I've got a simple form in my iPhone app. The form is laid out and managed via IB and the typical wiring (i.e. I am not creating this form programmatically).
One of the fields (and its associated label) should be shown only if a particular preference is set.
I could set the field and label's alpha to 0 and disable them in this case. The problem is that the fields below this now-invisible field would remain in the same place and there would be a big blank area. My goal is to have the screen look normal in either state.
Is there a way to programmatically remove (or add) UI elements and have those below shift up or down to make room? Or should I consider making a whole other NIB file for this second case? (and, if I do that, is there an easy way to share the common elements?)
Current UI with both controls shown
With Both http://img.skitch.com/20100704-bm41w6wtqkdgh1da99ihb7g32d.jpg
UI with optional control hidden via alpha == 0
Using Alpha to Hide http://img.skitch.com/20100704-q2sxrj3nf6ya68wp6ubn86n2pa.jpg
Desired UI with optional control hidden
Desired when hidden http://img.skitch.com/20100704-82r876pgctee8gb51ujg1dwj7k.jpg
I've seen a tutorial about this recently that involved moving a subview further down in the main view when a segmented control was selected. I believe it was an animation triggered by a beginAnimations:context:, but I can't find a reference to that tutorial right now.
Essentially, there were views under a view that were hidden, and one set was moved out of the way and the other controls unhidden.
When every UI element is linked to a IBOutlet pointer, e.g.
You can test each element's visibility by:
And move them around:
Or by some animation:
To hide an element:
To show an element:
Use the cocoa touch properties:
.hidden 1 .userInteractionEnabled 0
Or you could:
.alpha = 0