2

我正在尝试创建一个小游戏,并且在拖放对象时遇到问题:我在两个按钮上使用 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)) 语句。任何人都可以帮忙吗?

4

0 回答 0