Modifying the iOS Keyboard with Xamarin
Brian Ponath
61

public void KeyboardUpNotification(NSNotification notification) { // get the keyboard size RectangleF keyboardFrame = (RectangleF)UIKeyboard.BoundsFromNotification(notification); // Find what opened the keyboard foreach (UIView view in this.View.Subviews) { if (view.IsFirstResponder) _activeview = view; } // Determine if we need to scroll up or down. // Bottom of the controller = initial position + height + offset _bottom = (float)(_activeview.Frame.Y + _activeview.Frame.Height + Offset); // Calculate how far we need to scroll _scrollamount = (float)(keyboardFrame.Height — (View.Frame.Size.Height — _bottom)); //Move view up if (_scrollamount > 0) { //Subtract the scrolledamount. We can’t do this subtraction above because the calculations won’t work correctly. _bottom -= _scrolledamount; _scrollamount = (float)(keyboardFrame.Height — (View.Frame.Size.Height — _bottom)); _scrolledamount += _scrollamount; ScrollTheView(false); } //Reset the view. else { ScrollTheView(true); } }

The compiler keeps throwing an exception on the following line of code:

// Bottom of the controller = initial position + height + offset _bottom = (float)(_activeview.Frame.Y + _activeview.Frame.Height + Offset);

I do not understand what I am doing wrong with this code. Because if I explicitly give it a float value it works. Which defeats the whole point.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.