2011年6月20日月曜日

画面にタッチしたときの動作を取得 UITouch

//<<タッチ開始>>
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];
NSInteger taps = [touch tapCount];
[super touchesBegan:touches withEvent:event];
NSLog(@"タップ開始 %f, %f  タップ数:%d", location.x, location.y, taps);
}

//<<タッチ移動>>
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint oldLocation = [touch previousLocationInView:self.view];
CGPoint newLocation = [touch locationInView:self.view];
[super touchesMoved:touches withEvent:event];
NSLog(@"指の動き:%f , %f から %f, %f", oldLocation.x, oldLocation.y, newLocation.x, newLocation.y);
}

//<<タッチ終了>>
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];
[super touchesEnded:touches withEvent:event];
NSLog(@"タップ終了 %f, %f", location.x, location.y);
}
//指が画面から離れた際に呼び出されます。指が離れた場所を取得し、ログに出力します。

0 件のコメント: