2013-11-04 63 views
1

我正在寻找一种方式,我如何能绑定ios手势像UILongPressGestureRecognizer到ICommand或MvxCommand在MvvmCross,谢谢。MvvmCross绑定iOS手势

PS:我找到了一个例子here,但我无法弄清楚如何做到这一点。

+0

,范例的位可你想不明白?如果你用'LongPress'替换'Tap',那么什么是不行的 - 是否有编译错误?还是运行时异常? – Stuart

+0

我添加了类LongPressBehaviour和BehaviourExtensions,但是当我做label.LongPress();它不承认它。 –

回答

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