method export not call

i am using IUIViewControllerAnimatedTransitioning, IUIViewControllerTransitioningDelegate for my project

it is my modalViewController

public partial class ModalViewController : UIViewController, IUIViewControllerAnimatedTransitioning, IUIViewControllerTransitioningDelegate
{
private bool isPresenting = true;

    public ModalViewController()
    {
    }

    public ModalViewController(IntPtr handle) : base(handle)
    {
    }
    public override void LoadView()
    {
        base.LoadView();
        this.TransitioningDelegate = this;
        this.ModalPresentationStyle = UIModalPresentationStyle.Custom;
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        UITapGestureRecognizer tap = new UITapGestureRecognizer(() => DismissViewController(true, null));
        bgView.AddGestureRecognizer(tap);
    }
    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);
        bgView.BackgroundColor = UIColor.Black.ColorWithAlpha(0.5f);
    }
    public void AnimateTransition(IUIViewControllerContextTransitioning transitionContext)
    {
        var containerView = transitionContext.ContainerView;
        var toViewController = transitionContext.GetViewControllerForKey(UITransitionContext.ToViewControllerKey);
        var toVC = toViewController;
        isPresenting = !isPresenting;
        var frame = contentView.Frame;
        if (isPresenting == true)
        {
            containerView.AddSubview(toVC.View);
            bgView.Alpha = 0;
            contentView.Frame = new CGRect(0, containerView.Frame.Height, frame.Width, frame.Height);

            UIView.Animate(TransitionDuration(transitionContext), 0, UIViewAnimationOptions.CurveEaseInOut, () =>
            {
                contentView.Frame = new CGRect(0, containerView.Frame.Height - frame.Height, frame.Width, frame.Height);
                bgView.Alpha = 1;
            }, () =>
            {
                transitionContext.CompleteTransition(true);
            });
        }
        else
        {
            contentView.Frame = new CGRect(0, containerView.Frame.Height - frame.Height, frame.Width, frame.Height);
            bgView.Alpha = 1;
            UIView.Animate(TransitionDuration(transitionContext), 0, UIViewAnimationOptions.CurveEaseInOut, () =>
            {
                bgView.Alpha = 0;
                contentView.Frame = new CGRect(0, containerView.Frame.Height, frame.Width, frame.Height);
            }, () =>
            {
                transitionContext.CompleteTransition(true);
            });
        }

    }


    public double TransitionDuration(IUIViewControllerContextTransitioning transitionContext)
    {
        return 0.8f;
    }

    [Export("animationControllerForPresentedController:presentingController:sourceController:")]
    public IUIViewControllerAnimatedTransitioning GetAnimationControllerForPresentedController(UIViewController presented, UIViewController presenting, UIViewController source)
    {
        return this;
    }

    [Export("animationControllerForDismissedController:")]
    public IUIViewControllerAnimatedTransitioning GetAnimationControllerForDismissedController(UIViewController dismissed)
    {
        return this;
    }

}

I'm using the following code to present it (in a touch event):

var pvc = Storyboard.InstantiateViewController("demoStoryboard") as ModalViewController;

            pvc.ModalPresentationStyle = UIModalPresentationStyle.Custom;
            this.PresentViewController(pvc, true, null);

i have issue : the GetAnimationControllerForPresentedController function not call when present view but GetAnimationControllerForDismissedController alway call when i dismissed it.
how can i fix it please

Answers

Sign In or Register to comment.