两个根演示文稿之间的MvvmCross v5动画

时间:2017-05-17 10:44:41

标签: ios animation xamarin mvvmcross

我有两个标有osgi:install -s mvn:com.tuts.abhinav/rest-service/1.0-SNAPSHOT 属性的iOS视图:MvxRootPresentation没有包装到导航控制器中,而LoginView包含在导航控制器中。

当我调用MainView时,这两个视图之间没有动画。所有后续视图都像往常一样动画(在NavigationController中)。

如何为此过渡设置动画?

1 个答案:

答案 0 :(得分:6)

好的,我自己做过:)我必须添加自定义演示文稿属性和自定义演示者:

public class AnimatedRootPresentationAttribute : MvxRootPresentationAttribute
{
}

public class MyPresenter : MvxIosViewPresenter
{
    public MyPresenter(IUIApplicationDelegate appDelegate, UIWindow window)
        : base(appDelegate, window)
    {
    }

    protected override void RegisterAttributeTypes()
    {
        base.RegisterAttributeTypes();

        _attributeTypesToShowMethodDictionary.Add(typeof(AnimatedRootPresentationAttribute),
            (viewController, attribute, request) => ShowAnimatedRootViewController(
                viewController, (AnimatedRootPresentationAttribute)attribute, request));
    }

    private void ShowAnimatedRootViewController(
        UIViewController viewController,
        AnimatedRootPresentationAttribute attribute,
        MvxViewModelRequest request)
    {
        ShowRootViewController(viewController, attribute, request);
        AddAnimation();
    }

    private void AddAnimation()
    {
        var transition = new CATransition
        {
            Duration = 0.2,
            Type = CAAnimation.TransitionMoveIn,
            Subtype = CAAnimation.TransitionFromTop
        };

        _window.RootViewController.View.Layer.AddAnimation(transition, null);
    }
}