Monotouch MKMapView UIGestureRecognizer问题

时间:2013-06-18 10:08:35

标签: xamarin.ios mapkit uigesturerecognizer

我在IB中的MapView中添加了3个手势识别器,长按,平移和放大器。紧要关头。他们的代表是文件的所有者。我这样设置 -

public override void ViewDidLoad ()
{
        base.ViewDidLoad ();

        PanGestureRecognizer.AddTarget(s => { Console.WriteLine("Pan"); } );
        LongPressGestureRecognizer.AddTarget(s => { Console.WriteLine("Long press"); } );
        PinchGestureRecognizer.AddTarget(s => { Console.WriteLine("Pinch"); } );

}

我也实现了这个 -

public bool ShouldRecognizeSimultaneously (UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
{
    return true;
}

问题是,只有Long Press手势识别器会做任何事情,其他人完全被忽略。

欢迎任何想法/建议!

1 个答案:

答案 0 :(得分:1)

作为Monotouch的新手,我没有意识到当我将IB中的MapView委托设置为我的ViewController时,实际上并不起作用。我需要创建一个委托,它是UIGestureRecognizerDelegate的子类,并将gestureRecognizer的委托设置为此,我以编程方式添加了gestureRecognizer(虽然这可能不是必需的) -

private class GestureRecognizerDelegate : UIGestureRecognizerDelegate
{
    public override bool ShouldRecognizeSimultaneously (UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
    {
        return true;
    }
}


public override void ViewDidLoad ()
{
    base.ViewDidLoad ();

    UIPinchGestureRecognizer pinchGestureRecognizer = new UIPinchGestureRecognizer(s => { /* do stuff here */ } );

    GestureRecognizerDelegate gestureRecognizerDelegate = new GestureRecognizerDelegate();
    pinchGestureRecognizer.Delegate = gestureRecognizerDelegate;

    MapView.AddGestureRecognizer(pinchGestureRecognizer);
}

然后,通过将MapView的ZoomEnabled属性设置为false,我可以控制地图缩放的方式(在我的情况下,我不得不阻止地图放大超过某个阈值,我的客户对方式不满意你可以放大&然后它会弹回我的预设值,我在MapView委托中使用了RegionChanged。你不爱客户吗?