シンプルなフルスクリーンの UIView があります。ユーザーが画面をタップすると、x、y を書き出す必要があります
Console.WriteLine ("{0},{1}",x,y);
そのためにどの API を使用する必要がありますか?
シンプルなフルスクリーンの UIView があります。ユーザーが画面をタップすると、x、y を書き出す必要があります
Console.WriteLine ("{0},{1}",x,y);
そのためにどの API を使用する必要がありますか?
MonoTouch では (C# で質問したため...前の回答は正しいのですが :)、次のようになります。
public override void TouchesBegan (NSSet touches, UIEvent evt)
{
base.TouchesBegan (touches, evt);
var touch = touches.AnyObject as UITouch;
if (touch != null) {
PointF pt = touch.LocationInView (this.View);
// ...
}
UITapGestureRecognizer を使用することもできます。
var tapRecognizer = new UITapGestureRecognizer ();
tapRecognizer.AddTarget(() => {
PointF pt = tapRecognizer.LocationInView (this.View);
// ...
});
tapRecognizer.NumberOfTapsRequired = 1;
tapRecognizer.NumberOfTouchesRequired = 1;
someView.AddGestureRecognizer(tapRecognizer);
Gesture Recognizer は、タッチを再利用可能なクラスにカプセル化するので便利です。
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
printf("Touch at %f , %f \n" , [touch locationInView:self.view].x, [touch locationInView:self.view].y);
}