Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View Transition Animation

I have this code:

- (void) displayView:(int)intNewView{

NSLog(@"%i", intNewView);
[currentView.view removeFromSuperview];
[currentView release];

switch (intNewView) {
    case 1:
        currentView = [[EnterView alloc] init];
        break;
    case 2:
        currentView = [[MainMenuView alloc] init];
        break;
    case 3:
        currentView = [[DetailsView alloc] init];
        break;
    case 4:
        currentView = [[PhotosView alloc] init];
        break;
    case 5:
        currentView = [[CustomUITableViewViewController alloc] init];
        break;
}

[self.view addSubview:currentView.view]; 

}

This code successfully transitions views, however its not very spectacular as you can imagine (the view simply switches with no animation). I'm wondering if there is a simple way to add any kind of simple view transition animation here? I can't figure out how to implement any of the example I've found online. Any animation would suffice, just something to spice things up a bit :)

Thanks,

Jack

like image 719
Jack Nutkins Avatar asked May 22 '11 17:05

Jack Nutkins


People also ask

How do you animate a view?

Create ImageView in the activity_main. xml along with buttons that will add animation to the view. Navigate to the app > res > layout > activity_main. xml.

What is a transition animation?

Transitions are animations used to keep users oriented during user interface (UI) state changes and object manipulations, and make those changes feel smooth instead of jarring. Good transitions feel natural, often giving the illusion that users are interacting with real-world objects.

What is transition animation in Android?

Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.


1 Answers

You can simply use basic core animations:

Like this:

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:2];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft  forView:self.view cache:YES];


[self.view addSubview:currentView.view];

[UIView commitAnimations];

You can try different UIViewAnimationTransitions, for the "forView" you enter the view that currently is on the screen. Hope that helped.

like image 57
JulenissensHjelper Avatar answered Sep 23 '22 15:09

JulenissensHjelper