Best Practice: Animating a View on iPhone

If I want to use Core Animation to fade out a view and exit the screen - is it okay to have a UIView in the same NIB as the view it is being pulled into? Should I create the view in another NIB file and load it from there? I am looking for animating three small views on the display at the same time with user action. I wanted to build views in IB. Look for a best practice type answer here.

+1


source to share


3 answers


You can have three views as separate UIViews inside one XIB, or lay out three views in one view (otherwise you have to position them in code). Set their initial alpha values ​​to 0.0, and then fading them out 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 would not put each of the three views in separate XIBs if you plan on displaying them all together. I usually just break things like that if they are parts of separate "screens" that will never be shown together.

+3


source


Apple recommends using one XIB in a UIViewController / UIView combination. This is because if you place multiple ViewCOntrollers and Views in the same XIB, they all load at the same time and use memory for all XIB elements, even if one of them is on screen.

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



If you just load subviews as described above, you can build them in the same xib, or programmatically create them in viewDidLoad or viewWillAppear (which will be called after the xib has loaded with your "base" view.

+1


source


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

0


source







All Articles