PDA

View Full Version : Animating views in iPhone




sujithkrishnan
May 22, 2008, 08:59 AM
Hi all..

I am making use of the following code in my iphone app to make an animation of the particular view.
This code works pretty good in viewDidAppear method, but not in viewWillAppear method and loadView method , Why so???

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.75];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[UIView commitAnimations];

Also i want to display the view with animation, here what happen is that the view will appear and then go for an animation.




The app what i am trying to developing should lokks like each views are each side of a cube...

help me!!!!
thanks..



Sayer
May 22, 2008, 02:02 PM
The viewWillAppear method and loadView method are to let your program setup any objects or data you need before the view is shown.

There is a lot of really helpful sample code from Apple that covers all of the basic tasks for making a new iPhone program.

This one deals with transitioning views:

http://developer.apple.com/iphone/library/samplecode/ViewTransitions/index.html

Part of the learning Cocoa is learning where you insert your own code on top of the framework to do something different for your program. In Apple's sample code they create a custom subclass of the UIView and use that to manage transitions to other subviews.

Once you understand that you are simply adding a few custom pieces to the existing large frameworks in iPhone OS X you will more easily figure out how to make your iPhone program (or Mac cocoa program).

tacoman667
May 22, 2008, 02:09 PM
viewDidAppear is basically after all objects and instances have been allocated and initialized for that view and right before it "releases" the view to be seen in the UI, it fires off one last event handler.

The other 2 are before and during events. Those are probably not working as well/not at all because the objects you are relying on probably are not completely initialized yet.