【问题标题】:problem with counter of collision of two imageViews两个imageViews碰撞计数器的问题
【发布时间】:2011-09-18 09:38:55
【问题描述】:

这是我的代码:

-(void)moveTheImage{
for (NSUInteger i = 0; i < [views count]; i++) {
    imageView = [views objectAtIndex:i];
    X = [[XArray objectAtIndex:i] floatValue];
    Y = [[YArray objectAtIndex:i] floatValue];
imageView.center=CGPointMake(imageView.center.x + X, imageView.center.y + Y);
    [self interaction];

}

}

-(void)interaction{
if(!intersectFlag)
{   



    if(CGRectIntersectsRect(imageView.frame,centre.frame))    
    {
        intersectFlag = YES;    
        label.text= [NSString stringWithFormat:@"%d", counti];
        [imageView removeFromSuperview];
        ++counti;
    }
}
else
{
    if(!CGRectIntersectsRect(imageView.frame,centre.frame))
    {
        intersectFlag = NO;
    }
}

} 我希望每次“imageView”和“centre”之间发生冲突时计数增加1,但我的问题是计数增加太多,更确切地说,它增加了“center”中的“imageView”然后它没有t 触摸“中心”计数器停止。请问我该如何解决?对不起我的英语我是法国人:/

【问题讨论】:

    标签: iphone xcode animation uiimageview collision-detection


    【解决方案1】:

    如果“intersectFlag”标记了单个 imageView 对象的状态,那么它应该是该对象的成员,而不是在所有 imageView 之间共享。

    【讨论】:

    • 我不太明白你能解释一下吗?
    猜你喜欢
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    相关资源
    最近更新 更多