Friday, 24 February 2012

For the rotating any object round round from center in iphone

CALayer *orbit1 = [CALayer layer];
    orbit1.bounds = CGRectMake(0, 0, 200, 200);
    orbit1.position = self.view.center;
    orbit1.cornerRadius = 100;
    orbit1.borderColor = [UIColor clearColor].CGColor;
    orbit1.borderWidth = 1.5;
   
    CALayer *planet1 = [CALayer layer];
    planet1.bounds = CGRectMake(0, 0, 20, 20);
    planet1.position = CGPointMake(100, 0);
    planet1.cornerRadius = 10;
    planet1.backgroundColor = [UIColor redColor].CGColor;
    [orbit1 addSublayer:planet1];
   
    CABasicAnimation *anim1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    anim1.fromValue = [NSNumber numberWithFloat:0];
    anim1.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
    anim1.repeatCount = HUGE_VALF;
    anim1.duration = 8.0;
    [orbit1 addAnimation:anim1 forKey:@"transform"];
   
    [self.view.layer addSublayer:orbit1];


No comments:

Post a Comment