/// <summary>
        /// Handleses the keyboard notifications.
        /// </summary>
        /// <param name="notification">Notification.</param>
        private void HandlesKeyboardNotifications(NSNotification notification)
        {
            // Check if the keyboard is becoming visible
            bool keyboardVisibile = notification.Name == UIKeyboard.WillShowNotification;

            // Start an animation, using values from the keyboard
            UIView.BeginAnimations("AnimateForKeyboard");
            UIView.SetAnimationBeginsFromCurrentState(true);
            UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification) <= 0.0f ? 0.3f : UIKeyboard.AnimationDurationFromNotification(notification));
            UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification));

            // Pass the notification, calculating keyboard height, etc.
            bool landscape = InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight;

            if (keyboardVisibile)
            {
                var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
                _keyboardChanged.OnNext(new KeyboardData {
                    IsVisible = keyboardVisibile, Height = landscape ? keyboardFrame.Width : keyboardFrame.Height
                });
            }
            else
            {
                var keyboardFrame = UIKeyboard.FrameBeginFromNotification(notification);
                _keyboardChanged.OnNext(new KeyboardData {
                    IsVisible = keyboardVisibile, Height = landscape ? keyboardFrame.Width : keyboardFrame.Height
                });
            }

            // Commit the animation
            UIView.CommitAnimations();
        }
Example #2
0
        private void OnKeyboardNotification(NSNotification notification)
        {
            //Check if the keyboard is becoming visible
            bool visible = notification.Name == UIKeyboard.WillShowNotification;

            //Start an animation, using values from the keyboard
            UIView.BeginAnimations("AnimateForKeyboard");
            UIView.SetAnimationBeginsFromCurrentState(true);
            UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification));
            UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification));

            //Pass the notification, calculating keyboard height, etc.
            if (visible)
            {
                var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
                OnKeyboardChanged(visible, keyboardFrame.Height);
            }
            else
            {
                var keyboardFrame = UIKeyboard.FrameBeginFromNotification(notification);
                OnKeyboardChanged(visible, keyboardFrame.Height);
            }

            //Commit the animation
            UIView.CommitAnimations();
        }
Example #3
0
            protected virtual void KeyboardWillShowNotification(NSNotification notification)
            {
                this.Scroll.ScrollEnabled = true;
                var scroll = this.GetScrollView();

                if (this.defaultInsetsAreSet == false)
                {
                    this.defaultInsetsAreSet     = true;
                    this.defaultContentInsets    = scroll.ContentInset;
                    this.defaultIndicatorsInsets = scroll.ScrollIndicatorInsets;
                }

                var keyboardBounds     = UIKeyboard.FrameEndFromNotification(notification);
                var contentBottomInset =
                    UIApplication.SharedApplication.StatusBarOrientation.IsLandscape() ? keyboardBounds.Width : keyboardBounds.Height;
                var contentInsets = new UIEdgeInsets(scroll.ContentInset.Top, default(nfloat), contentBottomInset, default(nfloat));

                scroll.ScrollIndicatorInsets = contentInsets;
                scroll.ContentInset          = contentInsets;
                var activeView = this.KeyboardGetActiveView();

                if (activeView != null)
                {
                    this.ignoreScroling = true;
                    UIView.Animate(
                        UIKeyboard.AnimationDurationFromNotification(notification),
                        () => scroll.ScrollRectToVisible(scroll.ConvertRectFromView(activeView.Frame, activeView.Superview), false),
                        () => this.ignoreScroling = false);
                }
            }
        private void KeyboardWillHide(NSNotification notification)
        {
            // See comments in KeyboardWillShow.
            RectangleF frameEnd = UIKeyboard.FrameEndFromNotification(notification);
            double     duration = UIKeyboard.AnimationDurationFromNotification(notification);
            uint       curve    = UIKeyboard.AnimationCurveFromNotification(notification);


            UIEdgeInsets insets = _textView.ContentInset;

            insets.Bottom -= frameEnd.Height;

            insets         = _textView.ScrollIndicatorInsets;
            insets.Bottom -= frameEnd.Height;


            //Old method, using a frame.
            //RectangleF newFrame = new RectangleF(_textView.Frame.Left, _textView.Frame.Top, _textView.Frame.Width, View.Frame.Height);
            UIView.Animate(duration, delegate
            {
                UIView.SetAnimationCurve((UIViewAnimationCurve)curve);

                _textView.ContentInset          = insets;
                _textView.ScrollIndicatorInsets = insets;

                //Old method, using a frame.
                //_textView.Frame = newFrame;
            });
        }
Example #5
0
    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);

        obs1 = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, delegate(NSNotification n){
            var kbdRect   = UIKeyboard.BoundsFromNotification(n);
            var duration  = UIKeyboard.AnimationDurationFromNotification(n);
            var frame     = View.Frame;
            frame.Height -= kbdRect.Height;
            UIView.BeginAnimations("ResizeForKeyboard");
            UIView.SetAnimationDuration(duration);
            View.Frame = frame;
            UIView.CommitAnimations();
        });

        obs2 = NSNotificationCenter.DefaultCenter.AddObserver("UIKeyboardWillHideNotification", delegate(NSNotification n){
            var kbdRect   = UIKeyboard.BoundsFromNotification(n);
            var duration  = UIKeyboard.AnimationDurationFromNotification(n);
            var frame     = View.Frame;
            frame.Height += kbdRect.Height;
            UIView.BeginAnimations("ResizeForKeyboard");
            UIView.SetAnimationDuration(duration);
            View.Frame = frame;
            UIView.CommitAnimations();
        });
    }
Example #6
0
 void KeyboardWillHide(NSNotification obj)
 {
     UIView.Animate(UIKeyboard.AnimationDurationFromNotification(obj), () =>
     {
         consBottomVCharaterNumber.Constant = 0;
     });
 }
Example #7
0
        private void OnKeyboardNotification(NSNotification notification)
        {
            if (!IsViewLoaded)
                return;

            var visible = notification.Name == UIKeyboard.WillShowNotification;

            UIView.BeginAnimations("AnimateForKeyboard");
            UIView.SetAnimationBeginsFromCurrentState(true);
            UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification));
            UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification));

            var landscape = InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight;
            if (visible)
            {
                var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
                OnKeyboardChanged(visible, landscape ? keyboardFrame.Width : keyboardFrame.Height);
            }
            else
            {
                var keyboardFrame = UIKeyboard.FrameBeginFromNotification(notification);
                OnKeyboardChanged(visible, landscape ? keyboardFrame.Width : keyboardFrame.Height);
            }

            UIView.CommitAnimations();
        }
Example #8
0
        private void OnKeyboardNotification(NSNotification notification)
        {
            if (!IsViewLoaded)
            {
                return;
            }

            //Check if the keyboard is becoming visible
            var visible = notification.Name == UIKeyboard.WillShowNotification;

            //Start an animation, using values from the keyboard
            UIView.BeginAnimations("AnimateForKeyboard");
            UIView.SetAnimationBeginsFromCurrentState(true);
            UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification));
            UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification));

            //Pass the notification, calculating keyboard height, etc.
            bool landscape     = InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight;
            var  keyboardFrame = visible
                                ? UIKeyboard.FrameEndFromNotification(notification)
                                : UIKeyboard.FrameBeginFromNotification(notification);

            OnKeyboardChanged(visible, landscape ? keyboardFrame.Width : keyboardFrame.Height);

            //Commit the animation
            UIView.CommitAnimations();
        }
 /// <summary>
 /// resizes the view when the keyboard comes up or goes away, allows our scroll view to work
 /// </summary>
 protected void KeyboardOpenedOrClosed(NSNotification n, string openOrClose)
 {
     // if it's opening
     if (openOrClose == "Open")
     {
         Console.WriteLine("Keyboard opening");
         // declare vars
         RectangleF kbdFrame          = UIKeyboard.BoundsFromNotification(n);
         double     animationDuration = UIKeyboard.AnimationDurationFromNotification(n);
         RectangleF newFrame          = contentViewSize;
         // resize our frame depending on whether the keyboard pops in or out
         newFrame.Height -= kbdFrame.Height;
         // apply the size change
         UIView.BeginAnimations("ResizeForKeyboard");
         UIView.SetAnimationDuration(animationDuration);
         scrlMain.Frame = newFrame;
         UIView.CommitAnimations();
     }
     else                 // if it's closing, resize
                          // declare vars
     {
         double animationDuration = UIKeyboard.AnimationDurationFromNotification(n);
         // apply the size change
         UIView.BeginAnimations("ResizeForKeyboard");
         UIView.SetAnimationDuration(animationDuration);
         scrlMain.Frame = contentViewSize;
         UIView.CommitAnimations();
     }
 }
Example #10
0
        public static void ReactToKeyboardWillHideNotification(UIView notifiedView, UIView activeView, bool isCalledFromChildView, NSNotification notification)
        {
            if (activeView == null)
            {
                return;
            }

            var scrollView = activeView.FindSuperviewOfType(notifiedView, typeof(UIScrollView)) as UIScrollView;

            if (scrollView == null)
            {
                return;
            }

            // find the topmost scrollview (fix problem with RootElement)
            var nextSuperView = scrollView;

            while (nextSuperView != null)
            {
                scrollView    = nextSuperView;
                nextSuperView = scrollView.FindSuperviewOfType(isCalledFromChildView ? notifiedView.Superview : notifiedView, typeof(UIScrollView)) as UIScrollView;
            }

            // Reset the content inset of the scrollView and animate using the current keyboard animation duration
            var animationDuration = UIKeyboard.AnimationDurationFromNotification(notification);
            var contentInsets     = new UIEdgeInsets(0.0f, 0.0f, 0.0f, 0.0f);

            UIView.Animate(animationDuration, delegate {
                scrollView.ContentInset          = contentInsets;
                scrollView.ScrollIndicatorInsets = contentInsets;
            });
        }
        private void WillHide(NSNotification notification)
        {
            var duration = UIKeyboard.AnimationDurationFromNotification(notification);

            this.KeyboardWillHide?.Invoke(this, new KeyboardNotificationEventArgs(TimeSpan.FromSeconds(duration), RectangleF.Empty));

            this.isShowing = false;
        }
Example #12
0
 void KeyboardWillHide(NSNotification obj)
 {
     UIView.Animate(UIKeyboard.AnimationDurationFromNotification(obj), () =>
     {
         bottomSpace.Constant = 0;
         View.LayoutIfNeeded();
     });
 }
Example #13
0
        void KeyboardWillShow(NSNotification obj)
        {
            var keyBoardSize = UIKeyboard.FrameEndFromNotification(obj);

            UIView.Animate(UIKeyboard.AnimationDurationFromNotification(obj), () =>
            {
                consBottomVCharaterNumber.Constant = keyBoardSize.Height;
            });
        }
Example #14
0
        private void OnKeyboardNotification(NSNotification notification)
        {
            try
            {
                if (!IsViewLoaded)
                {
                    return;
                }

                //Check if the keyboard is becoming visible
                var visible = notification.Name == UIKeyboard.WillShowNotification;
                //Start an animation, using values from the keyboard
                UIView.BeginAnimations("AnimateForKeyboard");
                UIView.SetAnimationBeginsFromCurrentState(true);
                UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification));
                UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification));
                var keyboardFrame = visible ? UIKeyboard.FrameEndFromNotification(notification) : UIKeyboard.FrameBeginFromNotification(notification);

                // Move up the textfield when the keyboard comes up
                if (visible)
                {
                    nfloat Offset = 0;
                    var    Source = (configTableView.Source as DB_ConfigTableSource);

                    if (Source != null)
                    {
                        var Height = configTableView.ContentSize.Height / 2;



                        var Value = Source.CurrentOffestY;

                        if (Value >= Height)
                        {
                            Offset = Height / 2;


                            //Source.CurrentOffestY = Offset;
                        }
                    }

                    configscroll.ContentOffset = new CGPoint(0, (keyboardFrame.Height / 2) + Offset);
                    //configTableView.ScrollRectToVisible(new CoreGraphics.CGRect(0, 1, 1, 1), true);
                }
                else
                {
                    configscroll.ContentOffset = new CGPoint(0, 0);
                }
                //NSDictionary info = notification.UserInfo;
                //Commit the animation
                UIView.CommitAnimations();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception Occured in OnKeyBoardNotification method due to " + ex.Message);
            }
        }
Example #15
0
            protected virtual void KeyboardWillHideNotification(NSNotification notification)
            {
                this.Scroll.ScrollEnabled = false;
                var activeView = this.KeyboardGetActiveView();

                // Reset the content inset of the ScrollView and animate using the current keyboard animation duration
                var animationDuration = activeView == null ? 0 : UIKeyboard.AnimationDurationFromNotification(notification);

                UIView.Animate(animationDuration, this.ResetScrollView);
            }
Example #16
0
        void KeyboardWillShow(NSNotification obj)
        {
            var keyBoardSize = UIKeyboard.FrameEndFromNotification(obj);

            UIView.Animate(UIKeyboard.AnimationDurationFromNotification(obj), () =>
            {
                bottomSpace.Constant = keyBoardSize.Height;
                View.LayoutIfNeeded();
            });
        }
Example #17
0
        private void KeyboardWillChange(nfloat bottom, NSNotification notification)
        {
            var duration = UIKeyboard.AnimationDurationFromNotification(notification);

            FooterView.SetNeedsLayout();

            FooterViewBottomConstraint.Constant = bottom;

            UIView.Animate(
                duration: duration,
                animation: FooterView.LayoutIfNeeded);
        }
Example #18
0
        private void OnKeyboardWillHideNotification(NSNotification notification)
        {
            if (!IsViewLoaded || View.Window == null)
            {
                return;
            }

            double duration = UIKeyboard.AnimationDurationFromNotification(notification);

            //Pass the notification, calculating keyboard height, etc.

            UIView.Animate(duration, () => bottomContraint.Constant = 0, null);
        }
        private void WillShow(NSNotification notification)
        {
            if (this.isShowing)
            {
                return;
            }

            var duration       = UIKeyboard.AnimationDurationFromNotification(notification);
            var keyboardBounds = ((NSValue)notification.UserInfo.ObjectForKey(UIKeyboard.BoundsUserInfoKey)).RectangleFValue;

            this.KeyboardWillShow?.Invoke(this, new KeyboardNotificationEventArgs(TimeSpan.FromSeconds(duration), keyboardBounds));

            this.isShowing = true;
        }
Example #20
0
 private void OnKeyboardNotification(NSNotification notification)
 {
     if (IsViewLoaded)
     {
         //Check if the keyboard is becoming visible
         bool visible = notification.Name == UIKeyboard.WillShowNotification;
         UIView.Animate(UIKeyboard.AnimationDurationFromNotification(notification), () => {
             UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification));
             var frame      = UIKeyboard.FrameEndFromNotification(notification);
             keyboardOffset = visible ? frame.Height : 0;
             ViewDidLayoutSubviews();
         });
     }
 }
        public static IObservable <CGRect> ViewportObservable(this BaseViewController viewController)
        {
            NSObject hideNotification = null;
            NSObject showNotification = null;
            var      subject          = new Subject <CGRect>();

            var notificationAction = new Action <NSNotification>(notification =>
            {
                if (viewController.IsViewLoaded)
                {
                    //Start an animation, using values from the keyboard
                    UIView.BeginAnimations("AnimateForKeyboard");
                    UIView.SetAnimationBeginsFromCurrentState(true);
                    UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification));
                    UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification));

                    //Pass the notification, calculating keyboard height, etc.
                    var nsValue = notification.UserInfo.ObjectForKey(UIKeyboard.FrameBeginUserInfoKey) as NSValue;
                    if (nsValue != null)
                    {
                        var kbSize  = nsValue.RectangleFValue.Size;
                        var view    = viewController.View.Bounds;
                        view.Height = view.Height - kbSize.Height;
                        subject.OnNext(view);
                    }

                    //Commit the animation
                    UIView.CommitAnimations();
                }
            });

            viewController.Appearing
            .Subscribe(_ =>
            {
                hideNotification = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, notificationAction);
                showNotification = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, notificationAction);
            });

            viewController.Disappearing
            .Where(_ => showNotification != null && hideNotification != null)
            .Subscribe(_ =>
            {
                NSNotificationCenter.DefaultCenter.RemoveObserver(hideNotification);
                NSNotificationCenter.DefaultCenter.RemoveObserver(showNotification);
            });

            return(subject);
        }
Example #22
0
        private void OnKeyboardWillShowNotification(NSNotification notification)
        {
            if (!IsViewLoaded || View.Window == null)
            {
                return;
            }


            double duration = UIKeyboard.AnimationDurationFromNotification(notification);

            //Pass the notification, calculating keyboard height, etc.
            var    keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
            nfloat newConstant   = keyboardFrame.Height;

            UIView.Animate(duration, () => bottomContraint.Constant = newConstant, null);
        }
        //========================================================================

        //========================================================================
        /// <summary>
        /// resizes the view when the keyboard comes up or goes away, allows our scroll view to work
        /// </summary>
        protected void KeyboardOpenedOrClosed(NSNotification n, string openOrClose)
        {
            //---- if it's opening
            if (openOrClose == "Open")
            {
                Console.WriteLine("Keyboard opening");

                //---- if it's actually been closed, resize
                if (this._keyboardClosed)
                {
                    //---- declare vars
                    RectangleF kbdFrame          = UIKeyboard.BoundsFromNotification(n);
                    double     animationDuration = UIKeyboard.AnimationDurationFromNotification(n);
                    RectangleF mainViewFrame     = this.View.Frame;

                    //---- resize our frame depending on whether the keyboard pops in or out
                    mainViewFrame.Height -= kbdFrame.Height;

                    //---- apply the size change
                    UIView.BeginAnimations("ResizeForKeyboard");
                    UIView.SetAnimationDuration(animationDuration);
                    this.View.Frame = mainViewFrame;
                    UIView.CommitAnimations();

                    //---- track our keyboard variable
                    this._keyboardClosed = false;
                }
            }
            else             //---- if it's closing, resize
            {
                //---- declare vars
                RectangleF kbdFrame          = UIKeyboard.BoundsFromNotification(n);
                double     animationDuration = UIKeyboard.AnimationDurationFromNotification(n);
                RectangleF mainViewFrame     = this.View.Frame;
                mainViewFrame.Height += kbdFrame.Height;

                //---- apply the size change
                UIView.BeginAnimations("ResizeForKeyboard");
                UIView.SetAnimationDuration(animationDuration);
                this.View.Frame = mainViewFrame;
                UIView.CommitAnimations();

                //---- track our keyboard variable
                this._keyboardClosed = true;
            }
        }
        private void OnKeyboardNotification(NSNotification notification)
        {
            var visible = notification.Name == UIKeyboard.WillShowNotification;

            keyboardHeight = visible
                ? UIKeyboard.FrameEndFromNotification(notification).Height
                : 0.0;

            if (finishedPresenting && ContainerView != null && PresentedViewController.PresentedViewController == null)
            {
                var animationDuration = UIKeyboard.AnimationDurationFromNotification(notification);
                AnimationExtensions.Animate(animationDuration, Animation.Curves.StandardEase, ContainerViewWillLayoutSubviews);
            }
            else if (PresentingViewController == null)
            {
                ContainerView?.SetNeedsLayout();
            }
        }
        void OnKeyboardChangeFrame(NSNotification obj)
        {
            var frame  = View.ConvertRectFromView(UIKeyboard.FrameEndFromNotification(obj), null);
            var curve  = UIKeyboard.AnimationCurveFromNotification(obj);
            var offset = View.Bounds.Height - frame.Y;

            View.LayoutIfNeeded();
            UIView.Animate(
                duration: UIKeyboard.AnimationDurationFromNotification(obj),
                delay: 0,
                options: (UIViewAnimationOptions)(curve << 16),
                animation: () => {
                messageEntryBottom.Constant = offset - BottomLayoutGuide.Length;
                View.LayoutIfNeeded();
                var ci    = TableView.ContentInset;
                ci.Bottom = offset + messageEntry.Frame.Height;
                TableView.ContentInset = ci;
            },
                completion: null
                );
        }
Example #26
0
        private void KeyboardWillShow(NSNotification notification)
        {
            // Get the frame of the keyboard at the end of the animation.
            RectangleF frameEnd = UIKeyboard.FrameEndFromNotification(notification);

            // Get the duration of the keyboard animation.
            double duration = UIKeyboard.AnimationDurationFromNotification(notification);

            // Get the animation curve (bounce etc);
            uint curve = UIKeyboard.AnimationCurveFromNotification(notification);

            // Because we are using a UITextView (UIScrollView) we are just going
            // to alter the insets. As seen below you can also alter the frame or anything else if you wish.
            UIEdgeInsets insets = _textView.ContentInset;

            insets.Bottom += frameEnd.Height;

            insets         = _textView.ScrollIndicatorInsets;
            insets.Bottom += frameEnd.Height;

            // Old method, using a frame.
            // RectangleF newFrame = new RectangleF(_textView.Frame.Left, _textView.Frame.Top, _textView.Frame.Width, _textView.Frame.Height - frameEnd.Height);
            // Create an animatin that goes for `duration` time.
            UIView.Animate(duration, delegate
            {
                // Set the animation curve.
                UIView.SetAnimationCurve((UIViewAnimationCurve)curve);

                // Set the new attributes to take place in the animation.
                _textView.ContentInset          = insets;
                _textView.ScrollIndicatorInsets = insets;

                // Old method, using a frame.
                //_textView.Frame = newFrame;

                // Animation just goes.
            });
        }
        /// <summary>
        /// Raises the keyboard notification event.
        /// </summary>
        /// <param name="notification">Notification.</param>
        private void OnKeyboardNotification(NSNotification notification)
        {
            try
            {
                if (!IsViewLoaded)
                {
                    return;
                }

                //Check if the keyboard is becoming visible
                var visible = notification.Name == UIKeyboard.WillShowNotification;

                //Start an animation, using values from the keyboard
                UIView.BeginAnimations("AnimateForKeyboard");
                UIView.SetAnimationBeginsFromCurrentState(true);
                UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification));
                UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification));

                var keyboardFrame = visible ? UIKeyboard.FrameEndFromNotification(notification) : UIKeyboard.FrameBeginFromNotification(notification);

                // Move up the textfield when the keyboard comes up
                if (visible)
                {
                    loginScrollView.ContentOffset = new CGPoint(0, keyboardFrame.Height / 2);
                }
                else
                {
                    loginScrollView.ContentOffset = new CGPoint(0, 0);
                }

                //Commit the animation
                UIView.CommitAnimations();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception Occured in OnKeyBoardNotification method due to " + ex.Message);
            }
        }
        // Resize the view depending on keyboard
        void OnKeyboardNotification(NSNotification notification)
        {
            if (!IsViewLoaded)
            {
                return;
            }

            // Check if the keyboard is becoming visible
            bool visible = notification.Name == UIKeyboard.WillShowNotification;

            // Start an animation, using values from the keyboard
            UIView.BeginAnimations("AnimateForKeyboard");
            UIView.SetAnimationBeginsFromCurrentState(true);
            UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification));
            UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification));

            // Pass the notification, calculating keyboard height, etc.
            if (visible)
            {
                CGRect keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
                //BtnKeyboardBottom.Constant = -keyboardFrame.Height;
                var navigationFrame = NavigationController.View.Frame;
                var newFrame        = new CGRect(0, 0, navigationFrame.Width, UIScreen.MainScreen.Bounds.Height - keyboardFrame.Height);
                NavigationController.View.Frame = newFrame;
            }
            else
            {
                //BtnKeyboardBottom.Constant = 0;
                var navigationFrame = NavigationController.View.Frame;
                var newFrame        = new CGRect(0, 0, navigationFrame.Width, UIScreen.MainScreen.Bounds.Height);
                NavigationController.View.Frame = newFrame;
            }

            View.LayoutIfNeeded();

            // Commit the animation
            UIView.CommitAnimations();
        }
        /// <summary>
        /// resizes the view when the keyboard comes up or goes away, allows our scroll view to work
        /// </summary>
        protected void KeyboardOpenedOrClosed(NSNotification n, string openOrClose)
        {
            //---- if it's opening
            if (openOrClose == "Open")
            {
                Console.WriteLine("Keyboard opening");

                //---- declare vars
                RectangleF kbdFrame          = UIKeyboard.BoundsFromNotification(n);
                double     animationDuration = UIKeyboard.AnimationDurationFromNotification(n);

                //---- get the current view's bounds
                RectangleF newFrame = this.View.Bounds;
                //---- shrink the frame's height
                newFrame.Height -= kbdFrame.Height;

                //---- apply the size change
                UIView.BeginAnimations("ResizeForKeyboard");
                UIView.SetAnimationDuration(animationDuration);
                this.scrlMain.Frame = newFrame;
                UIView.CommitAnimations();
            }
            else             //---- if it's closing, resize
            {
                //---- declare vars
                double animationDuration = UIKeyboard.AnimationDurationFromNotification(n);

                Console.WriteLine("resetting scroll view frame to: " + this._contentViewSize.ToString());

                //---- reset the content size back to what it was before
                UIView.BeginAnimations("ResizeForKeyboard");
                UIView.SetAnimationDuration(animationDuration);
                this.scrlMain.Frame = this._contentViewSize;
                UIView.CommitAnimations();
            }
        }
Example #30
0
        // Places the visible area of the scrollviewer at the top of the driver note.
        private void ObserveKeyboardShown(NSNotification notification)
        {
            var isKeyboardVisible = notification.Name == UIKeyboard.WillShowNotification;
            var keyboardFrame     = isKeyboardVisible
                                ? UIKeyboard.FrameEndFromNotification(notification)
                                : UIKeyboard.FrameBeginFromNotification(notification);

            var duration = UIKeyboard.AnimationDurationFromNotification(notification);

            UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification));

            AnimateAsync(duration, async() =>
            {
                // We need to wait until the default animation from iOS stops before ajusting the scrollviewer to the correct location.
                await Task.Delay(1000);
                var activeView = KeyboardGetActiveView();
                if (activeView == null)
                {
                    return;
                }

                var scrollView = activeView.FindSuperviewOfType(this, typeof(UIScrollView)) as UIScrollView;
                if (scrollView == null)
                {
                    return;
                }

                var contentInsets                = new UIEdgeInsets(0.0f, 0.0f, keyboardFrame.Height, 0.0f);
                scrollView.ContentInset          = contentInsets;
                scrollView.ScrollIndicatorInsets = contentInsets;

                // Move the active field to the top of the active view area.
                var offset = activeView.Frame.Y - ScrollingOffset;
                scrollView.ContentOffset = new CoreGraphics.CGPoint(0, offset);
            });
        }