通过触摸移动事件限制拖动距离

时间:2012-08-27 12:27:37

标签: iphone objective-c xcode opengl-es

为了使用OpenGL编辑图像,我提供了用户交互,这样,当用户移动手指时,图像会根据拖动方向进行编辑。但我想限制拖动。例如,用户应该只编辑某些部分如果拖动不受限制,我的图像纹理会变形,因为用户有可能将他/她的手指拖到整个屏幕或脸部(更具体地说)。

//这是代码

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    count++;
    NSLog(@"touches moved called");
    UITouch *touch = [[touches allObjects] objectAtIndex:0];
    if(count>2)
    {
        NSLog(@"Entered");
        count=0;
        self.view.userInteractionEnabled=NO;
    }
    else{
        updatepoint = [touch locationInView:self.view];
        mousex = updatepoint.x;
        mousey = self.view.bounds.size.height-updatepoint.y;
        grab = [self ripple_grab:mousex:mousey];
        [self drawFrame];
    }
}

1 个答案:

答案 0 :(得分:3)

我得到了解决方案

这是我更新的代码。如果有任何其他方法,请给我建议。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    count = 0;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    count++;
    NSLog(@"touches moved called");
    UITouch *touch = [[touches allObjects] objectAtIndex:0];
    if (count > 6)
    {
        NSLog(@"Entered");
       // count=0;
       // self.view.userInteractionEnabled = NO;
       //NSLog(@"line skipped");
    }
    else{
        NSLog(@"else Entered");
        updatepoint = [touch locationInView:self.view];
        mousex = updatepoint.x;
        mousey = self.view.bounds.size.height-updatepoint.y;
        grab = [self ripple_grab:mousex:mousey];
        [self drawFrame];
    }
}