Created
January 27, 2014 11:42
-
-
Save tluyben/8647131 to your computer and use it in GitHub Desktop.
Xamarin Slide up from bottom modal view transition for iOS 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TransitioningDelegate : UIViewControllerTransitioningDelegate | |
{ | |
public override IUIViewControllerAnimatedTransitioning PresentingController (UIViewController presented, UIViewController presenting, UIViewController source) | |
{ | |
return new ModalSlideUpAnimator (); | |
} | |
public override IUIViewControllerAnimatedTransitioning GetAnimationControllerForDismissedController (UIViewController dismissed) | |
{ | |
return new ModalSlideUpAnimator (true); | |
} | |
} | |
public class ModalSlideUpAnimator : UIViewControllerAnimatedTransitioning | |
{ | |
bool reverse = false; | |
float length = 0.5f; | |
public ModalSlideUpAnimator () | |
{ | |
} | |
public ModalSlideUpAnimator (float length) | |
{ | |
this.length = length; | |
} | |
public ModalSlideUpAnimator(bool reverse) { | |
this.reverse = reverse; | |
} | |
public ModalSlideUpAnimator(float length, bool reverse) { | |
this.reverse = reverse; | |
this.length = length; | |
} | |
public override double TransitionDuration (IUIViewControllerContextTransitioning transitionContext) | |
{ | |
return length; | |
} | |
public override void AnimateTransition (IUIViewControllerContextTransitioning transitionContext) | |
{ | |
var inView = transitionContext.ContainerView; | |
var fromVC = transitionContext.GetViewControllerForKey (UITransitionContext.FromViewControllerKey); | |
var fromView = fromVC.View; | |
var toVC = transitionContext.GetViewControllerForKey (UITransitionContext.ToViewControllerKey); | |
var toView = toVC.View; | |
var frame = toView.Frame; | |
if (reverse) { | |
inView.InsertSubviewBelow (toView, fromVC.View); | |
} else { | |
inView.AddSubview (toView); | |
toView.Frame = new System.Drawing.RectangleF (0, inView.Frame.Height, frame.Width, frame.Height); | |
} | |
UIView.Animate (TransitionDuration (transitionContext), () => { | |
if (reverse) { | |
fromView.Frame = new System.Drawing.RectangleF (0, inView.Frame.Height, frame.Width, frame.Height); | |
} else { | |
toView.Frame = new System.Drawing.RectangleF (0, UIApplication.SharedApplication.StatusBarFrame.Size.Height, frame.Width, frame.Height); | |
} | |
}, () => { | |
transitionContext.CompleteTransition (true); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment