2012-08-27 127 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]; 
    } 
}