-1

我在屏幕上有 4 个苹果和 4 个橙子,还有 2 个篮子,每个篮子一个。我成功地将苹果和橙子拖到各自的篮子中。我希望在所有物品都放入篮子后出现下一个屏幕按钮。

如何计算所有物品都放在他们的篮子里?: 我的代码

    CGPoint location = [touch locationInView:touch.view];
    apple.center = location;

   if (apple.center.x == 233 || apple.center.y == 368)
   {
    apple.hidden = YES;
   }
4

1 回答 1

0

使用 2 个int计数器:numberOfApplesInBasketnumberOfOrangesInBasket

CGPoint location = [touch locationInView:touch.view];
apple.center = location;

if (apple.center.x == 233 || apple.center.y == 368)
{
  apple.hidden = YES;
  numberOfApplesInBasket += 1;
  if (numberOfApplesInBasket == 4 && numberOfOrangesInBasket == 4) {
    // Do your thing
  }
}
于 2012-12-30T11:04:14.400 回答