2012-08-27 122 views
2

为了使用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]; 
    } 
} 

回答

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]; 
    } 
}