0

我有一个视图,其中包含用户可以拖动的对象和几个启动动画的按钮。触摸按钮时动画开始,但所有对象都回到起始位置..为什么?

NSMutableArray *arrayAntaChiusura1 = [NSMutableArray array];

for(int i = 0; i <= 5; i++)
{
    [arrayAntaChiusura1 addObject:[UIImage imageWithContentsOfFile:
                                   [[NSBundle mainBundle]
                                    pathForResource: [NSString stringWithFormat:@"anta_sx%d", 6-i]
                                    ofType:@"png"]]];
}

UIImageView *immagineAntaChiusura1;

immagineAntaChiusura1 = [[UIImageView alloc] initWithFrame:CGRectMake(283, 82, 120, 130)];

immagineAntaChiusura1.animationImages = arrayAntaChiusura1;
immagineAntaChiusura1.animationDuration = tempo_ante;
immagineAntaChiusura1.animationRepeatCount = 1;
[immagineAntaChiusura1 startAnimating];
[self.view addSubview:immagineAntaChiusura1]; // i think this line is the problem

提前感谢您的帮助,我无法自己摆脱困境!

4

2 回答 2

0

When you are doing the animation with the Images , You have to add those images in array smartly . Your code looks fine . Only one line in which I have doubt is :

[arrayAntaChiusura1 addObject:[UIImage imageWithContentsOfFile:
                               [[NSBundle mainBundle]
                                pathForResource: [NSString stringWithFormat:@"anta_sx%d", 6-i]
                                ofType:@"png"]]];

All other is fine . Just check whether the images are arranged in the order or not .

于 2013-06-05T04:36:20.140 回答
0

I didn't understand your problem completely but If you want continuous animating objects then set repeat count to -1 that is equal to infinity as given below:-

UIImageView *immagineAntaChiusura1;

immagineAntaChiusura1 = [[UIImageView alloc] initWithFrame:CGRectMake(283, 82, 120, 130)];

immagineAntaChiusura1.animationImages = arrayAntaChiusura1;
immagineAntaChiusura1.animationDuration = 1.5;
immagineAntaChiusura1.animationRepeatCount = -1;
[immagineAntaChiusura1 startAnimating];
[self.view addSubview:immagineAntaChiusura1];
于 2013-06-05T04:36:26.647 回答