Я создаю UIImageView через таймер, который вызывается в touchesended и перемещает его. После завершения анимации я удаляю его объект. Если я касаюсь экрана непрерывно от 6 до 7 раз, одно изображение (созданное из блока кода таймера) не движется и поэтому не освобождается.
это мой код:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
flakeImage = [UIImage imageNamed:@"bubble.png"];
TimerView1=[NSTimer scheduledTimerWithTimeInterval:(0.1) target:self selector:@selector(onTimer:) userInfo:[NSValue valueWithCGPoint:location] repeats:NO];
}
- (void)onTimer:(id) sender {
NSValue *value=[TimerView1 userInfo];
CGPoint location = [value CGPointValue];
int time= [secLabel.text intValue];
int tick = 0;
tick = time+1;
secLabel.text = [NSString stringWithFormat:@"%.2i", tick];
double scale = 1 / round(random() % 100) + 1.0;
double speed = 1 / round(random() % 100) + 1.0;
UIImageView* flakeView1 = [[UIImageView alloc]initWithImage:flakeImage];
flakeView1.tag=100;
int endX = round(random() % 320);
int endY = round(random() % 480);
flakeView1.frame = CGRectMake(location.x, location.y, 35.0 * scale, 35.0 * scale);
[self.view addSubview:flakeView1];
[UIView beginAnimations:nil context:flakeView1];
[UIView setAnimationDuration:6 * speed];
flakeView1.frame = CGRectMake(endX,endY, 5.0 * scale, 5.0 * scale);
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
if(tick == 1)
{
[TimerView1 invalidate];
secLabel.text=[NSString stringWithFormat:@"0"];
}
}
- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
UIImageView *flakeView1 = context;
[flakeView1 removeFromSuperview];
[flakeView1 release];
flakeView1=nil;
}
Я не знаю, почему это происходит. Есть ли способ определить, движется ли это изображение или нет?
Я видел много постов, они предлагают использовать animationKeys. Как использовать это для определения, является ли изображение Анимацией или нет?