我正在使用MvvmCross作为我的应用程序并从iPhone开始 . 为了实现使用RequestNavigate和Close在视图之间导航的复杂性,我从MvxBaseTouchViewPresenter派生了一个新的演示者 . 到现在为止还挺好 .

我现在遇到的问题是,当先前可见的视图仍处于转换状态(打开或关闭)时,可以关闭或显示视图 . 我能想到解决这个问题的唯一方法是使用视图控制器的ViewDidAppear和ViewDidDisappear事件处理程序调用一个Action来执行下一个视图的显示,从而将显示推迟到上一个视图完成其转换之后 .

这意味着我必须添加:

public override void ViewDidDisappear(bool animated)
    {
        base.ViewDidDisappear(animated);

        DoPostTransitionAction();
    }

    public override void ViewDidAppear (bool animated)
    {
        base.ViewDidAppear (animated);

        DoPostTransitionAction();
    }

    private void DoPostTransitionAction()
    {
        if( _postTransitionAction != null)_postTransitionAction();
    }

    private Action _postTransitionAction;

    public void ShowActionAfterTransition( Action postTransitionAction)
    {
        if( this.IsBeingDismissed || this.IsBeingPresented)
        {
            _postTransitionAction = postTransitionAction;
        }
        else
        {
            _postTransitionAction = null;
            postTransitionAction();
        }
    }

查看控制器,介绍一个IEventViewController接口,让我添加代码并将演示者的Show方法更改为:

public override void Show(MvxShowViewModelRequest request)
    {
        // find the current top view as it will disappear as a result of
        // showing the requested view
        // note: this will be null for the first show request
        var topViewController = TopViewController;

        // if the request is to roll back an existing stack of views
        // then rollback to the bottom of the stack
        if (request.ClearTop && topViewController != null)
        {
            RollBackStack(topViewController);
        }

        // the top view is about to be 'covered' by the view requested
        // if the top view is transitioning (appearing or disappearing)
        // then wait for it to finish before showing the view requested
        var disappearingViewController = topViewController as IEventViewController;

        // if the top view is disappearing and it's of the 'event' type
        // delay calling Show until after the view has disappeared
        if( disappearingViewController != null)
        {
            // the top view has been requested to close and will fire the
            // 'transition complete' event when it has

            // register the action to perform when the top view has disappeared
            disappearingViewController.ShowActionAfterTransition (() =>
            {
                Show (CreateView(request), true);
            });
        }
        else
        {
            // show the view now as the top view is either not closing
            // or, if it is, is not going to say when it does

            // create a view controller of the type requested
            Show(CreateView(request), true);
        }
    }

我真正想要的是基类中的那些事件处理程序 . 我想知道没有我让自己偏离主要发展道路的机会是什么?部分类可能会这样做吗?