簡體   English   中英

兩個根演示文稿之間的MvvmCross v5動畫

[英]MvvmCross v5 animation between two root presentations

我有兩個標記為MvxRootPresentation屬性的iOS視圖: LoginView沒有包裝到導航控制器中,而MainView包含在導航控制器中。

當我調用ShowViewModel<MainViewModel>() ,這兩個視圖之間沒有動畫。 所有后續視圖都像往常一樣動畫(在NavigationController中)。

如何為此過渡設置動畫?

好的,我自己做了:)我必須添加我的自定義演示文稿屬性和自定義演示者:

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);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM