Monday, 28 September 2015

How To Implement UIAnimation In Ios/Iphone



==> With The Diffrent Scale , Transform And Afferemative Animation :-Using UIAnimation

#import "ViewController.h"

@interface ViewController ()
=> Here Declared And Iboutelet Of UIView For UIAnimation:


@property (weak, nonatomic) IBOutlet UIView *viewOne;
@property (weak, nonatomic) IBOutlet UIView *viewTwo;
@property (weak, nonatomic) IBOutlet UIView *viewThree;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)btnMove:(id)sender {
   
    CGRect currentRct = _viewOne.frame;
    currentRct.origin.x =  250;
   
   
/==> User Simple Animation
    [UIView animateWithDuration:0.6 animations:^{
        _viewOne.frame = currentRct;
    }];

   
==> Used Animatiuon with Completion Handler:

//    [UIView animateWithDuration:0.6 animations:^{
//        _viewOne.frame = currentRct;
//        _viewTwo.backgroundColor = [UIColor blueColor];
//       
//        _viewOne.backgroundColor = [UIColor redColor];
//    } completion:^(BOOL finished) {
////        _viewOne.backgroundColor = [UIColor redColor];
//    }];

   
   
  ==> Here Used UIAnimation With Options:

//    [UIView animateWithDuration:0.6 delay:0.2 options:UIViewAnimationOptionCurveEaseOut animations:^{
//        _viewTwo.frame = currentRct;
//    } completion:nil];

   
   ==> Here Used Animation with Spring effect
//    [UIView animateWithDuration:0.6 delay:0.0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:1 animations:^{
//        _viewThree.frame = currentRct;
//    } completion:^(BOOL finished) {
//        NSLog(@"DONE");
//    }];

   
   
}


- (IBAction)btnRotate:(id)sender {

//    [UIView animateWithDuration:0.6 animations:^{
//        _viewThree.transform = CGAffineTransformRotate(_viewThree.transform, 3.14/2);
////        _viewThree.transform = CGAffineTransformMakeRotation(M_PI);
//    }];
   

    CGAffineTransform rotate =CGAffineTransformRotate(_viewThree.transform, 3.14/2);

    CGAffineTransform scale  = CGAffineTransformScale(_viewThree.transform, 1.5, 1.5);
   
   
    CGAffineTransform trans = CGAffineTransformTranslate(CGAffineTransformConcat(rotate, scale), 300, 300);
   
    [UIView beginAnimations:@"animationDemo" context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.6];
   
    _viewThree.transform = trans;

   
    [UIView commitAnimations];
   
   
}
- (IBAction)btnScale:(id)sender {
   
   
    _viewTwo.transform = CGAffineTransformIdentity;
    [UIView animateWithDuration:0.6 animations:^{
      
//        _viewTwo.transform = CGAffineTransformScale(_viewTwo.transform, 2.0, 2.0);
       
       
//        _viewTwo.transform = CGAffineTransformTranslate(_viewTwo.transform, 10, -20);
       
       
//        _viewTwo.transform = CGAffineTransformMakeTranslation(40, 50);
//        _viewThree.transform = CGAffineTransformMakeScale(2.0, 2.0);
       
    }];
   
   
   
    //Alternate way
//    CGRect rect = _viewTwo.frame;
//    rect.size.height*=2;
//    rect.size.width*=2;
//   
//    CGPoint pntCenter = _viewTwo.center;
//   
//    [UIView animateWithDuration:0.5 animations:^{
//        _viewTwo.frame = rect;
//        _viewTwo.center = pntCenter;
//    }];
   
   
   
}


-(void)animationDidStart:(CAAnimation *)anim{
   
}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
   
}

@end