1
我正在尋找一種方式,我如何能綁定ios手勢像UILongPressGestureRecognizer到ICommand或MvxCommand在MvvmCross,謝謝。MvvmCross綁定iOS手勢
PS:我找到了一個例子here,但我無法弄清楚如何做到這一點。
我正在尋找一種方式,我如何能綁定ios手勢像UILongPressGestureRecognizer到ICommand或MvxCommand在MvvmCross,謝謝。MvvmCross綁定iOS手勢
PS:我找到了一個例子here,但我無法弄清楚如何做到這一點。
從你發現的例子,並從當前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);
,範例的位可你想不明白?如果你用'LongPress'替換'Tap',那麼什麼是不行的 - 是否有編譯錯誤?還是運行時異常? – Stuart
我添加了類LongPressBehaviour和BehaviourExtensions,但是當我做label.LongPress();它不承認它。 –