我有一个简单的全屏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);

手势识别器很好,因为它们将触摸封装到可重用的类中。

10-08 12:00