在CGRectIntersectsRect之后停止用户交互

时间:2014-07-08 08:22:04

标签: ios objective-c core-graphics cgrect

我正在尝试设置一个游戏的一小部分,用户将标签拖到另一个游戏上。如果他这样做,标签重置并且玩家点数增加。

问题在于,如果我按下标签,我会获得无限量的点,因为只要我将手指放在屏幕上,我创建的Rect就不会重置它的位置。

以下是代码:

- (void)viewDidLoad
{
    UIPanGestureRecognizer *panrecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePangesture:)];

    [self.dragMe addGestureRecognizer:panrecognizer];
}

- (void)handlePangesture:(UIPanGestureRecognizer *)gestureRecognizer
{
    self.dragMe.center = [gestureRecognizer locationInView:self.dragMe.superview];

    CGRect dragMerect = self.dragMe.frame;

    CGRect endZonerect = self.endZone.frame;

    if (CGRectIntersectsRect(dragMerect, endZonerect)) {

        dragMerect.origin.x = 100;
        dragMerect.origin.y = 100;
        self.dragMe.center = dragMerect.origin;

        Points++;

        self.points.text = [NSString stringWithFormat:@"Points: %d",Points];

        NSLog(@"Rect is Intersecting");

        NSLog(@"%d",Points);
    }
}

希望你们知道我在说什么以及如何解决它!

提前致谢,Niklas

1 个答案:

答案 0 :(得分:0)

如果您希望应用禁用所有userInteraction,请使用:

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

重置标签后别忘了启用它:

[[UIApplication sharedApplication] endIgnoringInteractionEvents];