OGeek|极客世界-中国程序员成长平台

标题: c# - MvvmCross - 如何添加自定义模态转换 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:33
标题: c# - MvvmCross - 如何添加自定义模态转换

我正在使用 MvvmCross 和 Xamarin 开发一个项目。我试图在呈现和关闭我的模态视图时添加自定义过渡。目前我是这样介绍的:

[MvxModalPresentation(WrapInNavigationController = true, ModalPresentationStyle = UIModalPresentationStyle.Custom)]
public partial class MyView : MvxViewController
{

并以这种方式解雇它:

NavigationController.DismissModalViewController(true);

所以我已经准备好我的动画,但我假设我需要将转换委托(delegate)设置为我创建的那个。我该怎么做?

我对 MvvmCross 还很陌生,因此非常感谢任何提示和技巧。谢谢!



Best Answer-推荐答案


我不确定,你真正想要在这里实现什么。

如果您正在寻找语法帮助。应该是这样的。

this.NavigationController.TransitioningDelegate = new MyOwnDelegate();


  internal class MyOwnDelegate : IUIViewControllerTransitioningDelegate
    {
        public IntPtr Handle => throw new NotImplementedException();

        public void Dispose()
        {
            //throw new NotImplementedException();
        }
    }

但通常人们使用,这个。如果有帮助,我也会给出一些语法

this.NavigationController.Delegate = new NavigationControllerDelegate();



 public class NavigationControllerDelegate : UINavigationControllerDelegate
{
    public NavigationControllerDelegate(IntPtr handle) : base(handle)
    {
    }
    public NavigationControllerDelegate()
    {
    }
    public override IUIViewControllerAnimatedTransitioning GetAnimationControllerForOperation(UINavigationController navigationController, UINavigationControllerOperation operation, UIViewController fromViewController, UIViewController toViewController)
    {
        var fromVcConformA = fromViewController as ICustomTransition;
        var fromVCConFromB = fromViewController as IWaterFallViewControllerProtocol;
        var fromVCCConformc = fromViewController as IHorizontalPageViewControllerProtocol;

        var toVcConformA = toViewController as ICustomTransition;
        var toVCConfromB = toViewController as IWaterFallViewControllerProtocol;
        var toVCCConformc = toViewController as IHorizontalPageViewControllerProtocol;

        if ((fromVcConformA != null) && (toVcConformA != null) && ((fromVCConFromB != null && toVCCConformc != null) || (fromVCCConformc != null && toVCConfromB != null)))
        {
            var transition = new CustomTransition();
            transition.presenting = operation == UINavigationControllerOperation.Pop;
            return transition;
        }
        else
        {
            return null;
        }
    }

}

关于c# - MvvmCross - 如何添加自定义模态转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52196061/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4