开发者

how to detect wether the UIImage is moving

I am creating an UIImageView through timer which is called in touchesended and moving it. After completion of animation I am removing its object. If I touch the screen continuously 6 to 7 times, one of the image(created from the timer code block) is not moving and so not deallocating..

this is my code:

    - (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"];
 开发者_JS百科   }


}


    - (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

    UIImageView *flakeView1 = context;
    [flakeView1 removeFromSuperview];
    [flakeView1 release];
    flakeView1=nil;
}

I dont know why it is happening..Is there any way to detect if that image is moving or not? I have seen many posts, they suggest to use animationKeys.How to use that for detecting if image is Animating or not?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜