MvvmCross v5 animation between two root presentations
I have two views of iOS, marked with the attribute MvxRootPresentation
: LoginView
no porting to navigation controller and MainView
with porting to navigation controller.
When I call ShowViewModel<MainViewModel>()
, there is no animation between these two views. All subsequent views are animated as usual (in the NavigationController).
How do I set up the animation for this transition?
+3
source to share
1 answer
Ok I did it myself :) I had to add my own presentation attribute and custom presenter:
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);
}
}
+5
source to share