Tuesday 22 January 2013

Animation


1 ->

[viewContent.layer addAnimation:[self getShakeAnimation] forKey:@"transform.scale"];
- (CAAnimation*)getShakeAnimation { 
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];

    animation.values = [NSArray arrayWithObjects:
                        [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0f, 1.0f, 0.0f)],
                        [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0f, 0.0f, 0.0f)],
                        [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI * 2, 0.0f, 1.0f, 0.0f)],nil];

 animation.duration = 0.8f;
 animation.delegate = self;


    return animation;
}
 

2 -> animate view from bottom to top


-(void)makeAnimation
{
    CGRect optionsFrame = {0,480,320,480};
    userNameEmailView.frame = optionsFrame;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [self.view addSubview:userNameEmailView];
    //optionsFrame.origin.x -= optionsFrame.size.width;
    optionsFrame.origin.y -= optionsFrame.size.height;
    userNameEmailView.frame = optionsFrame;
    [UIView commitAnimations];
}

3 -> Shake the view like error is generating


-(void)shakeTheView
{    
    CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"position"];
    [shake setDuration:0.1];
    [shake setRepeatCount:2];
    [shake setAutoreverses:YES];
    [shake setFromValue:[NSValue valueWithCGPoint:
                         CGPointMake(searchByCountryView.center.x - 15,searchByCountryView.center.y)]];
    [shake setToValue:[NSValue valueWithCGPoint:
                       CGPointMake(searchByCountryView.center.x + 15, searchByCountryView.center.y)]];
    [searchByCountryView.layer addAnimation:shake forKey:@"position"];
}

4 . -> Spin your view,best for loading type image


- (void)spinTheView
{
    [CATransaction begin];
    [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
    CGRect frame = [searchByCountryView frame];
    searchByCountryView.layer.anchorPoint = CGPointMake(0.5, 0.5);
    searchByCountryView.layer.position = CGPointMake(frame.origin.x + 0.5 * frame.size.width, frame.origin.y + 0.5 * frame.size.height);
    [CATransaction commit];

    [CATransaction begin];
    [CATransaction setValue:(id)kCFBooleanFalse forKey:kCATransactionDisableActions];
    [CATransaction setValue:[NSNumber numberWithFloat:2.0] forKey:kCATransactionAnimationDuration];

    CABasicAnimation *animation;
    animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    animation.fromValue = [NSNumber numberWithFloat:0.0];
    animation.toValue = [NSNumber numberWithFloat:2 * M_PI];
    animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
    animation.delegate = self;
    [searchByCountryView.layer addAnimation:animation forKey:@"rotationAnimation"];

    [CATransaction commit];
}

3 -> Load the view From left side

CATransition *animation = [CATransition animation]; [[self navigationController] pushViewController:elementController animated:NO]; [animation setDuration:0.45]; [animation setType:kCATransitionPush]; [animation setSubtype:kCATransitionFromLeft]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; [[elementController.view layer] addAnimation:animation forKey:@"SwitchToView1"];

No comments:

Post a Comment