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

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

问题描述

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

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 并在字典中传递一些参数来显示包含详细报告的新视图.这工作正常.

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)

在 Presenter 类中,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 提供扩展的新类

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天全站免登陆