两个 imageView 碰撞计数器的问题
这是我的代码:
-(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”和“center”之间发生碰撞时计数都会增加 1,但我的问题是计数增加太多,更确切地说,“center”中的“imageView”的计数会增加,然后当它不发生碰撞时,计数就会增加触摸“中心”计数器就会停止。请问我该如何解决这个问题?抱歉我的英语我是法国人:/
here is my code:
-(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;
}
}
}
I want that the count increase of 1 every time there is a collision between "imageView" and "centre" but my problem is that the count increase too much,more exactly it increase for "imageView" in "centre" then when it doesn't touch "centre" the counter stops.How can I solve this please ? sorry for my english I'm french :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果“intersectFlag”标记单个 imageView 对象的状态,那么它应该是该对象的成员,而不是在所有 imageView 之间共享。
If "intersectFlag" marks the state of a single imageView object then it should be a member of that object and not shared between all imageViews.