我正在寻找一种方法,如何将ios手势如UILongPressGestureRecognizer绑定到MvvmCross中的ICommand或MvxCommand,谢谢。
PS:我找到了一个例子here,但我无法弄清楚如何做到这一点。
答案 0 :(得分:0)
从您找到的示例和当前的MVVM Cross源代码中,我执行了以下操作
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);