我正在尝试创建一个小游戏,并且拖放对象时遇到问题:我在两个按钮上使用UIPanGestureRecognizer。我想要的是当按钮1和按钮2重叠时按钮2突出显示。我认为它应该发生在UIGestureRecognizerStateBegan中,所以我这样写了:
//This code to make button1 move
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
//This code to handle what happens when button 1 is dragged around
if (recognizer.state == UIGestureRecognizerStateBegan) {
//And this code to handle what happens when button1 and button2 overlap
if (CGRectContainsPoint([button2 frame], translation)) {
button2.highlighted = YES;
}
}
问题似乎来自if(CGRectContainsPoint([button2 frame],translation))语句。有人可以帮忙吗?