2

UILongPressGestureRecognizer のような iOS ジェスチャを MvvmCross の ICommand または MvxCommand にバインドする方法を探しています。

PS:ここで例を見つけましたが、その方法がわかりません。

4

1 に答える 1

0

あなたが見つけた例と現在のMVVMクロスソースから、私は次のことをしました

public static class MvxBehaviourExtensions
{
    public static MvxLongPressGestureRecognizerBehaviour LongPress(this UIView view)
    {
        var toReturn = new MvxLongPressGestureRecognizerBehaviour(view);
        return toReturn;
    }
}

public class MvxLongPressGestureRecognizerBehaviour
    : MvxGestureRecognizerBehavior<UILongPressGestureRecognizer>
{
    protected override void HandleGesture(UILongPressGestureRecognizer gesture)
    {
        // Long press recognizer fires continuously. This will ensure we fire
        // the command only once. Fire as soon as gesture is recognized as
        // a long press.
        if (gesture.State == UIGestureRecognizerState.Began)
        {
            FireCommand();
        }
    }

    public MvxLongPressGestureRecognizerBehaviour(UIView target)
    {
        var lp = new UILongPressGestureRecognizer(HandleGesture);

        AddGestureRecognizer(target, lp);
    }
}

そして縛る

set.Bind(this.LongPress()).For(lp => lp.Command).To(c => c.DoTheStuffCommand);
于 2016-01-14T21:01:49.127 に答える