ios view touch

方健發表於2014-08-14

參考:

步驟:
1.允許view響應

view.userInteractionEnabled = YES;  

2. 實現以下方法

touchesBegan:withEvent:          //觸控螢幕的最開始被呼叫
touchesMoved:withEvent:         //移動過程中被呼叫
touchesEnded:withEvent:         //動作結束時被呼叫
touchesCancelled:WithEvent:

3. 用 [[touches anyObject] locationInView:self] 取得座標

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
  CGPoint tappedPt = [[touches anyObject] locationInView:self];
  int     xPos = tappedPt.x;
  int     yPos = tappedPt.y;
  NSLog(@" touchesMovedxPos %i yPos %i ", xPos, yPos);
} 

相關文章