2012-04-21 44 views

回答

10

在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); 

手勢識別器很好,因爲它們將觸摸封裝到可重用類中。

3
-(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); 
}