1

私は自分のアプリケーションにMvvmCrossを使用しており、iPhoneから始めています。RequestNavigateとCloseを使用してビュー間を移動する際の高度な機能を実現するために、MvxBaseTouchViewPresenterから新しいプレゼンターを派生させました。ここまでは順調ですね。

私が今抱えている問題は、以前に表示されていたビューが開いているか閉じているかにかかわらず、ビューを閉じたり表示したりできることです。この問題を回避するために考えられる唯一の方法は、ビューコントローラーのViewDidAppearおよびViewDidDisappearイベントハンドラーを使用して、次のビューの表示を行うアクションを呼び出し、それによって前のビューが遷移を終了するまで表示を延期することでした。

これは、次を追加する必要があることを意味します。

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

私が本当に欲しいのは、基本クラスのイベントハンドラーです。私がメインの開発パスから離れることなく、どのようなチャンスがあるのだろうか?部分的なクラスはそれをするかもしれませんか?

4

0 に答える 0