MvvmCross ViewModel从左侧过渡 [英] MvvmCross ViewModel transition from the left

查看:99
本文介绍了MvvmCross ViewModel从左侧过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing an app for iOS using MvvmCross. On one of my Views I have some basic report data that is displayed in a tableview.

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

When the table row is touched a new view containing a detail report is displayed by making the call to ShowViewModel passing some parameters in a Dictionary. This works fine.

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

When the user swipes left or right the app needs to show the detail report for the next or previous item in the original list. I am doing this by updating some parameters and calling ShowViewModel again. The logic behind this is all working fine.

我的问题; ShowViewModel动画从右侧进入的新视图。当用户向左滑动时,这是完美的。然而,当向右滑动它似乎反直觉。如何让ShowViewModel从左侧进行动画制作或转换?

My problem; ShowViewModel animates the new view coming in from the right. This is perfect when the user has swiped left. However when swiping right it seems counter intuitive. How can I make ShowViewModel animate or transition in from the left side?

推荐答案

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

This is the solution I was able to come up with following the helpful pointers in the answer from Andrei N. In the end I opted for a TransitionFlipFromRight and TransitionFlipFromLeft when scrolling between detail reports. Hopefully it is useful to somebody else.

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

I already had a presenter class that was inherited from MvxModalSupportTouchViewPresenter

public class BedfordViewPresenter : MvxModalSupportTouchViewPresenter

在这个班级中我添加了一个属性MvxPresentationHint。

Within this class I added a property of MvxPresentationHint.

private MvxPresentationHint _presentationHint;

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

In the override of method ChangePresentation the above property is used to store the passed in parameter

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

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

Two new MvxPresentationHint class were declared (see later)

在演示者类中,Show方法被覆盖

In the presenter class the Show method was overridden

    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提供扩展的新类/ p>

A new class that provides extensions to a UINavigationController was created with the method PushControllerWithTransition

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应用程序项目。

All that needs to be defined now are the two new MvxPresentationHint class derivations. These belong in your Core class library project rather than the iOS application project.

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

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

我希望这对其他人试图帮助类似的东西

I hope this is a help to someone else trying to do something similar

这篇关于MvvmCross ViewModel从左侧过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆