Friday, 15 February 2013

Animate Label or Image in Xcode

.h File

#import <UIKit/UIKit.h>

@interface Animation : UIViewController
{
    IBOutlet UILabel *labltext;
}

@property(nonatomic,retain)IBOutlet UILabel *labltext;

@end


.m File

-(void)viewDidLoad
{
    labltext.frame=CGRectMake(45, 20, 97, 21);
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:6.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    labltext.frame=CGRectMake(181, 321, 97, 21);
    [UIView commitAnimations];
}


Spin A label

-(void)viewDidLoad
{
    labltext.frame=CGRectMake(45209721);
    [UIView beginAnimations:@"First" context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:6.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    labltext.frame=CGRectMake(1813219721);
    [UIView commitAnimations];
}


- (void)animationDidStop:(NSString *)animID finished:(BOOL)didFinish context:(void *)context
{
    if ([animID isEqualToString:@"First"])
    {
        [UIView beginAnimations:@"Last" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(10, 375, 100, 30);
        [UIView commitAnimations];
        
    }
    else if ([animID isEqualToString:@"Last"])
    {
        [UIView beginAnimations:@"Last1" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(220, 20, 100, 30);
        [UIView commitAnimations];
        
    }
    
    else if ([animID isEqualToString:@"Last1"])
    {
        [UIView beginAnimations:@"First1" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(10, 10, 100, 30);
        [UIView commitAnimations];
        
    }
    else if ([animID isEqualToString:@"First1"])
    {
        [UIView beginAnimations:@"First" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(220, 200, 100, 30);
        [UIView commitAnimations];
        
    }

}

No comments: