0

我有多个 Imageview,我正在划分 360 度/no.of.Imageviews 以获得旋转每个 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;
}

在这里我的问题是所有的图像视图一次开始动画。我想将图像视图一个接一个地旋转到一个角度。

任何想法将不胜感激,谢谢大家

4

0 回答 0