Skip to content

Instantly share code, notes, and snippets.

@Cheesebaron
Last active January 4, 2016 00:09
Show Gist options
  • Save Cheesebaron/8539458 to your computer and use it in GitHub Desktop.
Save Cheesebaron/8539458 to your computer and use it in GitHub Desktop.
private NSObject _notification;
private float _scrollAmount;
private double _animationDuration;
private UIViewAnimationCurve _animationCurve;
public override void ViewDidLoad()
{
...
_notification = UIKeyboard.Notifications.ObserveWillShow((s, e) =>
{
_animationDuration = e.AnimationDuration;
_animationCurve = e.AnimationCurve;
var r = UIKeyboard.FrameBeginFromNotification(e.Notification);
_scrollAmount = r.Height;
ScrollTheView(true);
});
}
private void ScrollTheView(bool scale)
{
UIView.BeginAnimations(string.Empty, IntPtr.Zero);
UIView.SetAnimationDuration(_animationDuration);
UIView.SetAnimationCurve(_animationCurve);
var frame = View.Frame;
if (scale)
frame.Height -= _scrollAmount;
else
frame.Height += _scrollAmount;
View.Frame = frame;
UIView.CommitAnimations();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment