//UItouchcode
// 容許多點觸發 [self.view setMultipleTouchEnabled:YES];
// 單擊或者移動時會觸發這個方法,而且只會調用一次ip
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"%s",func);rem
NSLog(@"%@",touches); //
UITouch * touch = [touches anyObject]; NSLog(@"%f",touch.timestamp); // 時間戳it
NSLog(@"%@",touch.view); // 打印手勢觸發的當前的視圖io
NSLog(@"%ld",touch.phase); // 觸發時的階段xevent
NSLog(@"%ld",touch.tapCount); // 點擊的次數方法
}im
// 單擊或者移動結束會觸發這個方法,而且只會調用一次時間戳
// 在屏幕上移動,會屢次調用touch
(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"%s",func);
UITouch * touch = [touches anyObject];
// 獲取上一個點的座標 // 相對於後面的參數這個view的座標 CGPoint prePoint = [touch previousLocationInView:self.view];
NSLog(@"%@",NSStringFromCGPoint(prePoint));
// 獲取當前點的座標 CGPoint currentPoint = [touch locationInView:self.view]; NSLog(@"%@",NSStringFromCGPoint(currentPoint));
CGFloat x = currentPoint.x - prePoint.x; CGFloat y = currentPoint.y - prePoint.y; _myView.center = CGPointMake(_myView.center.x+x, _myView.center.y+y);
} // 發生中斷(好比有來電時)進行調用
}