3
我有一個簡單的全屏UIView。當用戶在屏幕上點擊時,我需要寫出x,yMonotouch:獲取x.y或點擊UIView
Console.WriteLine ("{0},{1}",x,y);
什麼API我需要使用它嗎?
我有一個簡單的全屏UIView。當用戶在屏幕上點擊時,我需要寫出x,yMonotouch:獲取x.y或點擊UIView
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);
手勢識別器很好,因爲它們將觸摸封裝到可重用類中。
-(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);
}