Wednesday, February 1, 2012

A small examples with Animations

In iOS Sdk there are two types of animation which is used frequently.

with CoreAnimation

            CATransition *animation = [CATransition animation];
            [animation setDuration:1.5];
            [animation setType:kCATransitionMoveIn];
            [animation setSubtype:kCATransitionFromRight];
            [animation setSpeed:1.5];
            [[imageView layer] addAnimation:animation forKey:nil];

Here imageView is the view where you need to apply the animation. the view with come from right to left with the specific duration.

setDuration - to set the animation happen time
setType - to set the animation type

see CATransition class to get more details.

with UIAnimation

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationDelay:1.0];
        [UIView setAnimationDelegate:self];
        myImageView.alpha = 0.0;
        [UIView commitAnimations];

 Here i wanted to hide the myImageview. Instead of hiding with
    myImageView.hidden = YES;
I thought of adding some animation to hide the view.
It will hide the view in 2 sec after 1 sec of delay.


We have delegate methods to use more effectively. Just have a look at the Class.






No comments:

Post a Comment