views:

1892

answers:

3

If I'm looking to use Core Animation to fade a view in and out of display -- is it good practice to have the UIView in the same NIB as the view that it is being drawn into? Should I build the view in another NIB file and load it in from there? I'm looking to animate three small views into display simultaneously upon a user action. I wanted to construct the views in IB. Looking for a best practice type response here.

A: 

I think interface builder should be used as much as possible... so I recommend that each view be its own xib file... remember you can build a hierarchy of classes that extend from UIViewController if there is alot of overlap in functionality between the views.

diclophis
I have always thought it was funny that apple used IB very rarely in their example code ...
Harald Scheirich
Each xib file should map to a single subclass of UIViewController. If you're managing several views with the same UIViewController, they should all be in the same xib.
Kevin Ballard
+2  A: 

You can have the three views as separate UIViews inside a single XIB, or lay out the three views within one single view (otherwise, you'll have to position them in code). Set their initial alpha values to 0.0, then fading them in is as easy as:

[UIView beginAnimations:@"fade" context:nil];
[UIView setAnimationDuration:1.0];
myViewOne.alpha = 1.0;
myViewTwo.alpha = 1.0;
myViewThree.alpha = 1.0;
[UIView commitAnimations];

I wouldn't put each of the three views in separate XIBs if you're planning on displaying them all together. I usually only break stuff up like that if they're parts of separate "screens" which will never be shown together.

Arclite
+1  A: 

Apple recommends one XIB per UIViewController/UIView combination. This is because if you place several ViewCOntrollers and Views in the same XIB, they are all loaded at the same time and use up memory for all the elements of the XIB, even if just one is on screen.

The recommended method is to use MainWindow.xib to have proxys to each of the xibs (UIViewController/UIView combos) you plan on loading.

If you are just loading subviews, as above, you can construct them in the same xib, or build them programatically in viewDidLoad or viewWillAppear (which will be called after the xib is loaded with your "basic" view.

Corey Floyd