Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to show animation with objects

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 470
    Comment on it

    Animation On x and y axis.

    If we want to show some moving object on X or Y axis then we can use following code. Here we have taken one view and give some colour to it.

     CABasicAnimation *animation = [CABasicAnimation animation];
        animation.keyPath = @"position.x"; //view will move left to right ,if we want to show it from tom to bottom them write position.y
        animation.byValue = @378;
        animation.duration = 5; //time taken for movement
        
        [viewOutlet addAnimation:animation forKey:@"basic"];
        viewOutlet.layer.position = CGPointMake(455, 61);
        
        animation.beginTime = CACurrentMediaTime() + 0.5;
        
        [viewOutlet.layer addAnimation:animation forKey:@"basic"];
      viewOutlet.layer.position = CGPointMake(455, 111);

     

    Shake animation


    If we want to shake some object then we can use following code. In below code we applied animation on view.
     

    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
        animation.keyPath = @"position.x";
        animation.values = @[ @0, @10, @-10, @10, @0 ];
        animation.keyTimes = @[ @0, @(1 / 6.0), @(3 / 6.0), @(5 / 6.0), @1 ];
        animation.duration = 0.4;
        
        animation.additive = YES;
        
        [viewOutlet.layer addAnimation:animation forKey:@"shake"];
    
    

     

    Rotation Mode


    If we want our object should rotate in rotation mode then we can use following code.

        CGRect boundingRect = CGRectMake(-150, -150, 300, 300);
        
        CAKeyframeAnimation *orbit = [CAKeyframeAnimation animation];
        orbit.keyPath = @"position";
        orbit.path = CFAutorelease(CGPathCreateWithEllipseInRect(boundingRect, NULL));
        orbit.duration = 4;
        orbit.additive = YES;
        orbit.repeatCount = HUGE_VALF;
        orbit.calculationMode = kCAAnimationPaced;
        orbit.rotationMode = kCAAnimationRotateAuto; //used so that object should follows the rotation along the path.
        
        [viewOutlet.layer addAnimation:orbit forKey:@"orbit"];

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: