【发布时间】:2009-09-26 20:32:40
【问题描述】:
这是我的代码,用于让蝙蝠拍打翅膀并响应触摸。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSArray * imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"Bat1.png"],
[UIImage imageNamed:@"Bat2.png"],
[UIImage imageNamed:@"Bat3.png"],
[UIImage imageNamed:@"Bat2.png"],
[UIImage imageNamed:@"Bat1.png"],
[UIImage imageNamed:@"Bat4.png"],
[UIImage imageNamed:@"Bat5.png"],
[UIImage imageNamed:@"Bat6.png"],
[UIImage imageNamed:@"Bat5.png"],
[UIImage imageNamed:@"Bat4.png"],
nil];
UIImageView * batView = [[UIImageView alloc] initWithFrame:
CGRectMake(0, 0, 80, 56)];
batView.animationImages = imageArray;
batView.animationDuration = 0.70;
[follower1 addSubview:batView];
[batView startAnimating];
[UIImageView beginAnimations:@"follow" context:nil];
[UIImageView setAnimationDuration:1];
[UIImageView setAnimationBeginsFromCurrentState:YES];
UITouch *touch = [touches anyObject];
follower1.center = [touch locationInView:self];
[UIImageView commitAnimations];
[batView release];
}
问题在于,在第二次触摸后,动画会相互重叠,所以每次触摸后看起来下面都有很多蝙蝠!
【问题讨论】:
标签: iphone cocoa-touch animation uiimageview