0

I am having multiple Imageview's where I am dividing the 360 degrees/no.of.Imageviews to get an angle to rotate each Imageview.

#define angle ((2*M_PI)/13.0)

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    mainView.backgroundColor = [UIColor blackColor];


    for(currentIndex = 0; currentIndex < 13; currentIndex++)
    {

        UIImageView *imageView = [self getCardsWithAngle:(currentIndex*angle)];

        [mainView addSubview:imageView];
    }
}

-(UIImageView *)getCardsWithAngle:(float)aAngle 
{

    CGRect frame = CGRectMake(mainView.center.x+50, mainView.center.y-100, 250,200);
    CGPoint anchorPoint = CGPointMake(0.5,1.5);

    imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"card_1.png"]];
    imgView.frame = frame;
    imgView.backgroundColor = [UIColor clearColor];
    if(aAngle == 0.0)
    {
        imgView.layer.anchorPoint = anchorPoint;
        return imgView;
    }

    imgView.layer.anchorPoint = anchorPoint;


    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat:aAngle];
    rotationAnimation.duration = 3.0;


    rotationAnimation.removedOnCompletion = NO;
    rotationAnimation.fillMode = kCAFillModeForwards;
    rotationAnimation.delegate = self;
    [rotationAnimation setValue:[NSNumber numberWithFloat:aAngle] forKey:@"finalAngle"];

    [imgView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];



    return imgView;
}

Here My problem is all the imageviews start animating at a time. I want to rotate the image views to an angle one after another.

Any ideas will be appreciated, Thanks all

Madan Mohan
  • 8,764
  • 17
  • 62
  • 96
  • Why do you want that? Can't you achieve the "one after another" effect by setting a delay between the animations (using beginTime)? – David Rönnqvist Oct 23 '12 at 06:07
  • As I am new to this core animations stuff I dnt have idea how to use it... can u please elaborate how to use. – Madan Mohan Oct 23 '12 at 06:23
  • Try something like: `rotationAnimation.beginTime = CACurrentMediaTime() + aAngle;` That will cause each animation to start after the same number of seconds as the angle in radians. Obviously you may need to multiply aAngle with some constant to tweak the timing. – David Rönnqvist Oct 23 '12 at 06:27
  • @DavidRönnqvist: Okay tanq.. let me try n know u. – Madan Mohan Oct 23 '12 at 06:34

0 Answers0