MvvmCross ViewModel从左侧过渡

时间:2014-10-10 10:04:20

标签: ios xamarin.ios xamarin mvvmcross

我正在使用MvvmCross为iOS开发应用程序。在我的一个视图中,我有一些基本的报告数据显示在tableview中。

当触摸表格行时,通过调用ShowViewModel在Dictionary中传递一些参数来显示包含详细报告的新视图。这很好。

当用户向左或向右滑动时,应用程序需要显示原始列表中下一个或上一个项目的详细报告。我这样做是通过更新一些参数并再次调用ShowViewModel。这背后的逻辑一切正常。

我的问题; ShowViewModel为右侧的新视图设置动画。当用户向左滑动时,这是完美的。然而,当向右滑动它似乎反直觉。如何从左侧创建ShowViewModel动画或过渡?

3 个答案:

答案 0 :(得分:2)

如果您查看MvvmCross源代码here,您会看到默认行为如何显示ViewControllers

您需要通过执行以下操作来更改它: How to change the Push and Pop animations in a navigation based app

为此,一个想法是拥有一个自定义视图演示者并捕获导航到该特定视图模型(覆盖显示(IMvxTouchView视图))

或者,可能派生自UINavigationController,将其设置为MvvmCross以使用它(查看MvxSetup),并在某些事件上更改转换到该特定视图

类似于这个问题 How to specify view transitions on iPhone

答案 1 :(得分:2)

这是我能够在Andrei N的答案中提供有用指针后得出的解决方案。最后,我在详细报告之间滚动时选择了TransitionFlipFromRight和TransitionFlipFromLeft。希望它对其他人有用。

我已经有一个继承自MvxModalSupportTouchViewPresenter的演示者类

public class BedfordViewPresenter : MvxModalSupportTouchViewPresenter

在这个课程中,我添加了一个MvxPresentationHint的属性。

private MvxPresentationHint _presentationHint;

在方法ChangePresentation的覆盖中,上面的属性用于存储传入的参数

    public override void ChangePresentation (MvxPresentationHint hint)
    {
        _presentationHint = hint;
        base.ChangePresentation (hint);
    }

宣布了两个新的MvxPresentationHint类(见后文)

在演示者类中,重写了Show方法

    public override void Show(IMvxTouchView view)
    {
        if (_presentationHint is FlipFromRightPresentationHint) {
            var viewController = view as UIViewController;
            MasterNavigationController.PushControllerWithTransition (viewController, UIViewAnimationOptions.TransitionFlipFromRight);

        }
        else
            if (_presentationHint is FlipFromLeftPresentationHint)  {
                var viewController = view as UIViewController;
                MasterNavigationController.PushControllerWithTransition (viewController, UIViewAnimationOptions.TransitionFlipFromLeft);
            }
            else {
                base.Show (view);
            }

        _presentationHint = null;
    }

使用PushControllerWithTransition方法

创建了一个为UINavigationController提供扩展的新类
public static class UINavigationControllerExtensions
{
    public static void PushControllerWithTransition(this UINavigationController 
        target, UIViewController controllerToPush, 
        UIViewAnimationOptions transition)
    {
        UIView.Transition(target.View, 0.75d, transition, delegate() {
            target.PushViewController(controllerToPush, false);
        }, null);
    }
}

现在需要定义的是两个新的MvxPresentationHint类派生。这些属于您的Core类库项目,而不是iOS应用程序项目。

public class FlipFromLeftPresentationHint : MvxPresentationHint
{
    public FlipFromLeftPresentationHint ()
    {
    }
}

public class FlipFromRightPresentationHint: MvxPresentationHint
{
    public FlipFromRightPresentationHint ()
    {
    }
}

我希望这对其他试图做类似事情的人有所帮助

答案 2 :(得分:0)

分享我的android解决方案:

查看时

.intel_syntax noprefix
.globl main
.text

main:
  mov eax, 4
  push eax
  call factorial
  add esp, 4
  push eax
  push offset msg
  call printf
  add esp, 8
  mov eax, 0
 ret

factorial:
  push ebp
  mov ebp, esp
  push ecx
  push edx
  mov eax, [ebp+8]
  cmp eax, 0
  jne continue
  mov eax, 1
  pop edx
  pop ecx
  pop ebp
  ret

continue:
  push eax
  dec eax
  push eax
  call factorial
  add esp, 4
  pop ecx
  mul ecx
  pop edx
  pop ecx
  pop ebp
  ret

  .data
msg:  .asciz "%d\n"

手势侦听器:

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var view = base.OnCreateView(inflater, container, savedInstanceState);

        var layout = view.FindViewById<LinearLayout>(Resource.Id.swippeable);

        var swipeListener = new SwipeListener(this.Activity);

        swipeListener.OnSwipeLeft += (sender, e) => this.ViewModel.LeftCommand?.Execute(); //Here use command into view model

        swipeListener.OnSwipeRight += (sender, e) => this.ViewModel.RightCommand?.Execute();

        layout.SetOnTouchListener(swipeListener);

        return view;
    }