我想检查一下屏幕上某个特定位置是否有物体。我有一个带有框架(7,545,75,75)的图像视图和另一个移动的图像视图。我不希望它能够移动到与其他图像视图相同的位置,因此我需要能够判断对象是否存在于我试图移动到的位置。
以下是我的动态影像视图代码:
- (IBAction)moveForward:(id)sender
{
moveForwardCards--;
forwardLabel.text = [NSString stringWithFormat:@"%i left", moveForwardCards];
if (moveForwardCards == 0)
{
forwardButton.enabled = NO;
}
if (turtle.image.imageOrientation == UIImageOrientationRight)
{
turtle.frame = CGRectMake(turtle.frame.origin.x, turtle.frame.origin.y + 90, 75, 75);
}
else if (turtle.image.imageOrientation == UIImageOrientationLeft)
{
turtle.frame = CGRectMake(turtle.frame.origin.x, turtle.frame.origin.y - 90, 75, 75);
}
else if (turtle.image.imageOrientation == UIImageOrientationUp)
{
turtle.frame = CGRectMake(turtle.frame.origin.x + 90, turtle.frame.origin.y, 75, 75);
}
else if (turtle.image.imageOrientation == UIImageOrientationDown)
{
turtle.frame = CGRectMake(turtle.frame.origin.x - 90, turtle.frame.origin.y, 75, 75);
}
NSLog(@"turtle frame: %@", NSStringFromCGRect(turtle.frame));
}