IOS7 Custom Navigation Delegate UIViewControllerAnimatedTransitioning issue

alexvazquezalexvazquez MXMember
edited August 2014 in Xamarin.iOS

Hi I have create a custom navigation delegate for my UINavigationController in order to do custom animation when pushing views.

It seems is working fine but... I have detected some strange issues that maybe is something with my code.

I have attached the sample application for better reference but basically I have the following problems:

  1. Scroll to the bottom of the table (view), then tap on the blue button and you will see that source view moves up a little bit and then the new view is presented. So its like a "up flickering thing".

  2. Go back and now you will see that the source view height is a bigger... and now there is like small gap between the bottom of the screen.

Look here the source view how can I scroll to bottom and everything looks fine.

Now, when you push a view and then go back, look the bottom of the image (the gap I was mention before)

I can't show the "up flickering thing" here but if you download the code and see it in action you will understand.

Here is my CustomTransitionAnimator code:

` public class CustomTransitionAnimator : UIViewControllerAnimatedTransitioning
{
private float _navBarHeight = 0;
public CustomTransitionAnimator (UINavigationController navigationController)
{
_navBarHeight = navigationController.NavigationBar.Bounds.Height;

        }


        public bool Presenting { get; set; }

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

        public override void AnimateTransition (IUIViewControllerContextTransitioning transitionContext)
        {

            var inView = transitionContext.ContainerView;
            var toVC = transitionContext.GetViewControllerForKey(UITransitionContext.ToViewControllerKey);
            var toView = toVC.View;

            var fromVC = transitionContext.GetViewControllerForKey(UITransitionContext.FromViewControllerKey);
            var fromView = fromVC.View;

            toView.Alpha = 1;
            fromView.Alpha = 1;

            var toViewSize = new SizeF (toView.Frame.Size.Width, toView.Frame.Size.Height + _navBarHeight);
            var fromViewSize = new SizeF (fromView.Frame.Size.Width, fromView.Frame.Size.Height +_navBarHeight);


            inView.AddSubview(toView);

            if (Presenting)
            {

                var startToLocation = new PointF(UIScreen.MainScreen.Bounds.Width, _navBarHeight);
                var startToFrame =  new RectangleF(startToLocation,toViewSize);

                toView.Frame = startToFrame;

                UIView.Animate(TransitionDuration(transitionContext), () =>
                    {
                        var endToLocation = new PointF(0, _navBarHeight);
                        var endToFrame =  new RectangleF(endToLocation,toViewSize);
                        toView.Frame = endToFrame;

                        var endFromLocation = new PointF((UIScreen.MainScreen.Bounds.Width*-1), _navBarHeight);
                        var endFromFrame =  new RectangleF(endFromLocation,fromViewSize);
                        fromView.Frame = endFromFrame;
                        fromView.Alpha = 0;
                    }, () =>
                    {
                        transitionContext.CompleteTransition(true);
                    });

            }
            else
            {
                var startToLocation = new PointF((UIScreen.MainScreen.Bounds.Width*-1), _navBarHeight);
                var startToFrame =  new RectangleF(startToLocation,toViewSize);
                toView.Frame = startToFrame;

                UIView.Animate(TransitionDuration(transitionContext), () =>
                    {

                        var endToLocation = new PointF(0, _navBarHeight);
                        var endToFrame =  new RectangleF(endToLocation,toViewSize);
                        toView.Frame = new RectangleF(endToFrame.X,endToFrame.Y,endToFrame.Width,endToFrame.Height-_navBarHeight);

                        var endFromLocation = new PointF(UIScreen.MainScreen.Bounds.Width,_navBarHeight);
                        var endFromFrame =  new RectangleF(endFromLocation,fromViewSize);
                        fromView.Frame = endFromFrame;
                        fromView.Alpha = 0;
                    }, () =>
                    {
                        transitionContext.CompleteTransition(true);
                    });
            }



        }
    }`

Maybe my problem is in my animation code, can someone help me solving this wired issues?

Appreciate

Sign In or Register to comment.