Iphone 两个图像之间碰撞的计数器问题

Iphone 两个图像之间碰撞的计数器问题,iphone,xcode,timer,uiimageview,collision-detection,Iphone,Xcode,Timer,Uiimageview,Collision Detection,这是我的密码: -(void)collision { if(CGRectIntersectsRect(imageView.frame,centre.frame)){ [imageView removeFromSuperview]; count++; label.text= [NSString stringWithFormat:@"%d", count]; } } - (void)viewDidLoad { [supe

这是我的密码:

-(void)collision {

    if(CGRectIntersectsRect(imageView.frame,centre.frame)){

        [imageView removeFromSuperview];
        count++;
        label.text= [NSString stringWithFormat:@"%d", count];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];

    [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(collision) userInfo:nil repeats:YES];

    count=0;    
    scale=1;
}
有了这个代码,我的计数增加了不止一个,有时是34,有时是74或70,为什么

阻止接收器一直开火 再次要求将其从 它的运行循环


为什么
计数==0
?这是错误的吗?尝试
count=0
。也可以使用
++something
而不是
something++
,速度更快。为什么无效,我不想停止我的计时器?@bernard langue好的,我不是iOS多线程专家。但是如果不停止计时器,则无法立即删除视图。和。当图像被删除时,没有理由每秒调用选择器100次。我的建议是只在需要使用计时器时启动计时器,然后立即停止。我相信我也可以使用多个计时器。如何“仅在需要使用计时器时启动计时器,并在”[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(collision)userInfo:nil repeats:YES]之后立即停止它];启动计时器并-(无效)使其停止,不是吗?启动/停止点取决于你的应用程序行为,如果你需要让计时器保持工作状态,你可以在移除视图之前尝试使用计数器设置标签文本,希望这会有所帮助。
 - (void)invalidate