diff --git a/Chat/Chat/ChatViewController.cs b/Chat/Chat/ChatViewController.cs index 88d44a4b..aaf24b09 100644 --- a/Chat/Chat/ChatViewController.cs +++ b/Chat/Chat/ChatViewController.cs @@ -70,6 +70,7 @@ namespace Chat willHideToken = UIKeyboard.Notifications.ObserveWillHide (KeyboardWillHideHandler); willHideMenuToken = UIMenuController.Notifications.ObserveWillHideMenu (MenuWillHide); + UpdateTableInsets (); UpdateButtonState (); } @@ -88,15 +89,39 @@ namespace Chat BottomConstraint.Constant = View.Bounds.GetMaxY () - e.FrameEnd.GetMinY (); UIViewAnimationCurve curve = e.AnimationCurve; - UIView.Animate (e.AnimationDuration, 0, ConvertToAnimationOptions(e.AnimationCurve), ()=> { + UIView.Animate (e.AnimationDuration, 0, ConvertToAnimationOptions (e.AnimationCurve), () => { View.LayoutIfNeeded (); + Tuple changes = UpdateTableInsets (); + + // Move content with keyboard + var offset = TableView.ContentOffset; + offset.Y += changes.Item1 - changes.Item2; + TableView.ContentOffset = offset; }, null); } + // returns changes in ContentInsetY and ContentOffsetY values + Tuple UpdateTableInsets() + { + UIEdgeInsets oldInset = TableView.ContentInset; + CGPoint oldOffset = TableView.ContentOffset; + + nfloat hiddenHeight = TableView.Frame.GetMaxY () - Chat.Frame.GetMinY(); + + UIEdgeInsets newInset = oldInset; + newInset.Bottom = hiddenHeight; + + TableView.ContentInset = newInset; // this may change ContentOffset property implicitly + TableView.ScrollIndicatorInsets = newInset; + + return new Tuple (newInset.Bottom - oldInset.Bottom, TableView.ContentOffset.Y - oldOffset.Y); + } + UIViewAnimationOptions ConvertToAnimationOptions(UIViewAnimationCurve curve) { // Looks like a hack. But it is correct. // UIViewAnimationCurve and UIViewAnimationOptions are shifted by 16 bits + // http://stackoverflow.com/questions/18870447/how-to-use-the-default-ios7-uianimation-curve/18873820#18873820 return (UIViewAnimationOptions)((int)curve << 16); } diff --git a/Chat/Chat/ChatViewController.designer.cs b/Chat/Chat/ChatViewController.designer.cs index 166fec85..89448c78 100644 --- a/Chat/Chat/ChatViewController.designer.cs +++ b/Chat/Chat/ChatViewController.designer.cs @@ -15,6 +15,9 @@ namespace Chat [Outlet] UIKit.NSLayoutConstraint BottomConstraint { get; set; } + [Outlet] + UIKit.UIView Chat { get; set; } + [Outlet] UIKit.UIButton SendButton { get; set; } @@ -45,6 +48,11 @@ namespace Chat TextView.Dispose (); TextView = null; } + + if (Chat != null) { + Chat.Dispose (); + Chat = null; + } } } } diff --git a/Chat/Chat/MainStoryboard_iPhone.storyboard b/Chat/Chat/MainStoryboard_iPhone.storyboard index 53ecf844..07c584d7 100644 --- a/Chat/Chat/MainStoryboard_iPhone.storyboard +++ b/Chat/Chat/MainStoryboard_iPhone.storyboard @@ -17,36 +17,8 @@ - - - - - - - - - - - - - - - - - - - - - - - + @@ -116,10 +88,38 @@ + + + + + + + + + + + + + + + + + + + + + + - + @@ -130,6 +130,7 @@ +