protected virtual void KeyboardWillShow(NSNotification notification)
        {
            var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);

            OnKeyboardChanged(keyboardFrame.Height);
        }
Esempio n. 2
0
        void OnKeyBoardEnabled(NSNotification notification)
        {
            if (!IsViewLoaded)
            {
                return;
            }

            var    pageBounds           = Element.Bounds;
            double yPosition            = UIKeyboard.FrameBeginFromNotification(notification).Y - UIKeyboard.FrameEndFromNotification(notification).Y;
            var    propertiesViewBounds = new Rectangle(Element.PropertiesView.X, Element.PropertiesView.Y - yPosition, Element.PropertiesView.Width, Element.PropertiesView.Height);

            Element.PropertiesView.Layout(propertiesViewBounds);
        }
        void OnKeyboardNotification(NSNotification notification)
        {
            if (!IsViewLoaded)
            {
                return;
            }

            var frameBegin = UIKeyboard.FrameBeginFromNotification(notification);
            var frameEnd   = UIKeyboard.FrameEndFromNotification(notification);


            /*
             * UIView activeView = KeyboardGetActiveView();
             * if (activeView == null)
             *  return;
             *
             * UIScrollView scrollView = activeView.FindSuperviewOfType(this.View, typeof(UIScrollView)) as UIScrollView;
             * if (scrollView == null)
             *  return;
             *
             * RectangleF keyboardBounds = (RectangleF)UIKeyboard.FrameBeginFromNotification(notification);
             *
             * UIEdgeInsets contentInsets = new UIEdgeInsets(0.0f, 0.0f, keyboardBounds.Size.Height, 0.0f);
             * scrollView.ContentInset = contentInsets;
             * scrollView.ScrollIndicatorInsets = contentInsets;
             *
             * // If activeField is hidden by keyboard, scroll it so it's visible
             * CGRect viewRectAboveKeyboard = new CGRect(this.View.Frame.Location, new CGSize(this.View.Frame.Width, this.View.Frame.Size.Height - keyboardBounds.Size.Height));
             *
             * RectangleF activeFieldAbsoluteFrame = (RectangleF)activeView.Superview.ConvertRectToView(activeView.Frame, this.View);
             * // activeFieldAbsoluteFrame is relative to this.View so does not include any scrollView.ContentOffset
             *
             * // Check if the activeField will be partially or entirely covered by the keyboard
             * if (!viewRectAboveKeyboard.Contains(activeFieldAbsoluteFrame))
             * {
             *  // Scroll to the activeField Y position + activeField.Height + current scrollView.ContentOffset.Y - the keyboard Height
             *  CGPoint scrollPoint = new CGPoint(0.0f, activeFieldAbsoluteFrame.Location.Y + activeFieldAbsoluteFrame.Height + scrollView.ContentOffset.Y - viewRectAboveKeyboard.Height);
             *  scrollView.SetContentOffset(scrollPoint, true);
             * }*/


            /*    var page = Element as ContentPage;
             *  if (page != null && !(page.Content is ScrollView))
             *  {
             *
             *      var padding = page.Padding;
             *      page.Padding = new Thickness(padding.Left, padding.Top, padding.Right, padding.Bottom + frameBegin.Top - frameEnd.Top);
             *  }
             */

            var bounds    = Element.Bounds;
            var newBounds = new Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height - frameBegin.Top + frameEnd.Top);

            Element.Layout(newBounds);

            var cp = Element as SpixiContentPage;

            if (cp != null)
            {
                cp.recalculateLayout();
            }


            /*  //Check if the keyboard is becoming visible
             * var visible = notification.Name == UIKeyboard.WillShowNotification;
             *
             * //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);*/
        }
        private void KeyBoardUpNotification(NSNotification notifi)
        {
            _keyboardBounds = UIKeyboard.BoundsFromNotification(notifi);

            ViewDidLayoutSubviews();
        }
Esempio n. 5
0
        void PositionHUD(NSNotification notification)
        {
            float  keyboardHeight    = 0;
            double animationDuration = 0;

            UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;

            if (notification != null)
            {
                RectangleF keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
                animationDuration = UIKeyboard.AnimationDurationFromNotification(notification);

                if (notification.Name == UIKeyboard.WillShowNotification || notification.Name == UIKeyboard.DidShowNotification)
                {
                    if (IsPortrait(orientation))
                    {
                        keyboardHeight = keyboardFrame.Size.Height;
                    }
                    else
                    {
                        keyboardHeight = keyboardFrame.Size.Width;
                    }
                }
                else
                {
                    keyboardHeight = 0;
                }
            }
            else
            {
                keyboardHeight = VisibleKeyboardHeight;
            }

            RectangleF orientationFrame = UIScreen.MainScreen.Bounds;
            RectangleF statusBarFrame   = UIApplication.SharedApplication.StatusBarFrame;

            if (IsLandscape(orientation))
            {
                orientationFrame.Size = new SizeF(orientationFrame.Size.Height, orientationFrame.Size.Width);
                statusBarFrame.Size   = new SizeF(statusBarFrame.Size.Height, statusBarFrame.Size.Width);
            }

            float activeHeight = orientationFrame.Size.Height;

            if (keyboardHeight > 0)
            {
                activeHeight += statusBarFrame.Size.Height * 2;
            }

            activeHeight -= keyboardHeight;
            float posY = (float)Math.Floor(activeHeight * 0.45);
            float posX = orientationFrame.Size.Width / 2;

            if (!showToastCentered)
            {
                posY = activeHeight - 40;
            }

            PointF newCenter;
            float  rotateAngle;

            switch (orientation)
            {
            case UIInterfaceOrientation.PortraitUpsideDown:
                rotateAngle = (float)Math.PI;
                newCenter   = new PointF(posX, orientationFrame.Size.Height - posY);
                break;

            case UIInterfaceOrientation.LandscapeLeft:
                rotateAngle = (float)(-Math.PI / 2.0f);
                newCenter   = new PointF(posY, posX);
                break;

            case UIInterfaceOrientation.LandscapeRight:
                rotateAngle = (float)(Math.PI / 2.0f);
                newCenter   = new PointF(orientationFrame.Size.Height - posY, posX);
                break;

            default:                     // as UIInterfaceOrientationPortrait
                rotateAngle = 0.0f;
                newCenter   = new PointF(posX, posY);
                break;
            }

            if (notification != null)
            {
                UIView.Animate(animationDuration,
                               0, UIViewAnimationOptions.AllowUserInteraction, delegate {
                    MoveToPoint(newCenter, rotateAngle);
                }, null);
            }
            else
            {
                MoveToPoint(newCenter, rotateAngle);
            }
        }
        public void ResetContentInset(NSNotification notification)
        {
            UIView activeView = KeyboardGetActiveView();

            if (activeView == null)
            {
                return;
            }

            if (scrollType == ScrollType.SCROLLVIEW)
            {
                UIScrollView scrollView = activeView.FindSuperviewOfType(parentView, typeof(UIScrollView)) as UIScrollView;

                if (scrollView == null)
                {
                    return;
                }

                double animationDuration = 0.3f;
                if (notification != null)
                {
                    animationDuration = UIKeyboard.AnimationDurationFromNotification(notification);
                }

                UIView.Animate(animationDuration, delegate
                {
                    scrollView.ContentInset          = UIEdgeInsets.Zero;
                    scrollView.ScrollIndicatorInsets = UIEdgeInsets.Zero;
                });
            }
            else if (scrollType == ScrollType.TABLEVIEW)
            {
                UITableView tableView = activeView.FindSuperviewOfType(parentView, typeof(UITableView)) as UITableView;
                if (tableView == null)
                {
                    return;
                }

                double animationDuration = 0.3f;
                if (notification != null)
                {
                    animationDuration = UIKeyboard.AnimationDurationFromNotification(notification);
                }

                UIView.Animate(animationDuration, delegate
                {
                    tableView.ContentInset          = UIEdgeInsets.Zero;
                    tableView.ScrollIndicatorInsets = UIEdgeInsets.Zero;
                });
            }
            else if (scrollType == ScrollType.TEXTVIEW)
            {
                UITextView textView = activeView.FindSuperviewOfType(parentView, typeof(UITextView)) as UITextView;
                if (textView == null)
                {
                    return;
                }

                double animationDuration = 0.3f;
                if (notification != null)
                {
                    animationDuration = UIKeyboard.AnimationDurationFromNotification(notification);
                }

                UIView.Animate(animationDuration, delegate
                {
                    textView.ContentInset          = UIEdgeInsets.Zero;
                    textView.ScrollIndicatorInsets = UIEdgeInsets.Zero;
                });
            }
        }
        private void OnKeyboardNotification(NSNotification notification)
        {
            if (IsViewLoaded)
            {
                //Check if the keyboard is becoming visible
                bool visible = notification.Name == UIKeyboard.WillShowNotification;

                UIView activeView = FindFirstResponder(View);

                //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;
                if (visible)
                {
                    nfloat h = 0;
                    if (activeView != null)
                    {
                        h = activeView.Frame.Y;
                        UIView super = activeView.Superview;
                        while (super != null)
                        {
                            if (typeof(UIScrollView) == super.GetType())
                            {
                                h = h + super.Frame.Y - ((UIScrollView)super).ContentOffset.Y;
                            }
                            else
                            {
                                h = h + super.Frame.Y;
                            }
                            super = super.Superview;
                        }
                    }
                    var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
                    OnKeyboardChanged(visible, keyboardFrame.Height, h);
                    //OnKeyboardChanged (visible, landscape ? keyboardFrame.Width : keyboardFrame.Height,activeView.Frame.Y);
                }
                else
                {
                    nfloat h = 0;
                    if (activeView != null)
                    {
                        h = activeView.Frame.Y;
                        UIView super = activeView.Superview;
                        while (super != null)
                        {
                            if (typeof(UIScrollView) == super.GetType())
                            {
                                h = h + super.Frame.Y - ((UIScrollView)super).ContentOffset.Y;
                            }
                            else
                            {
                                h = h + super.Frame.Y;
                            }
                            super = super.Superview;
                        }
                    }
                    var keyboardFrame = UIKeyboard.FrameBeginFromNotification(notification);
                    OnKeyboardChanged(visible, keyboardFrame.Height, h);
                    //OnKeyboardChanged (visible, landscape ? keyboardFrame.Width : keyboardFrame.Height,activeView.Frame.Y);
                }

                //Commit the animation
                UIView.CommitAnimations();
            }
        }
        /// <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();
        }
Esempio n. 9
0
 protected override void KeyBoardUpNotification(NSNotification notification)
 {
     tagsTableView.ContentInset = new UIEdgeInsets(0, 0, UIKeyboard.FrameEndFromNotification(notification).Height, 0);
     base.KeyBoardUpNotification(notification);
 }
Esempio n. 10
0
        private void OnKeyboardNotification(NSNotification notification)
        {
            if (!IsViewLoaded)
            {
                return;
            }

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

            //Pass the notification, calculating keyboard height, etc.
            var keyboardFrame = visible ? UIKeyboard.FrameEndFromNotification(notification) : UIKeyboard.FrameBeginFromNotification(notification);

            OnKeyboardChanged(visible, ((float)keyboardFrame.Height));
        }
Esempio n. 11
0
        /// <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);
            }
        }
        private void OnKeyboardNotification(NSNotification notification)
        {
            if (!IsViewLoaded)
            {
                return;
            }

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

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

            OnKeyboardChanged(visible, keyboardFrame.Height);
        }
Esempio n. 13
0
        void keyboardWillHide(NSNotification notification)
        {
            CGRect bounds = UIKeyboard.BoundsFromNotification(notification);

            moveView(bounds, notification);
        }
        private void OnKeyboardNotification(NSNotification notification)
        {
            float neededOffset  = 0;
            var   visible       = notification.Name == UIKeyboard.WillShowNotification;
            var   keyboardFrame = visible ? UIKeyboard.FrameEndFromNotification(notification) : UIKeyboard.FrameBeginFromNotification(notification);

            if (visible)
            {
                KeyboardShown?.Invoke(this, (float)keyboardFrame.Height);
            }

            var  parentView = UIApplication.SharedApplication.KeyWindow.RootViewController.View;
            bool isSubview  = false;
            var  responder  = InputTools.FindFirstResponder(parentView);

            if ((responder == null) && (UIApplication.SharedApplication.KeyWindow.Subviews != null))
            {
                foreach (var subview in UIApplication.SharedApplication.KeyWindow.Subviews)
                {
                    responder = InputTools.FindFirstResponder(subview);
                    if (responder != null)
                    {
                        parentView = subview;
                        isSubview  = true;
                        break;
                    }
                }
            }

            if (responder != null)
            {
                var offsetFromBottom = getOffsetFromBottom(responder);
                if (responder.Tag > 0)
                {
                    var views = getTaggedViews(parentView, responder.Tag);
                    if (views.Any())
                    {
                        var offsets = new List <nfloat>();
                        foreach (var view in views)
                        {
                            offsets.Add(getOffsetFromBottom(view));
                        }

                        offsetFromBottom = offsets.Min();
                    }
                }

                if (keyboardFrame.Height > offsetFromBottom)
                {
                    neededOffset = (float)(keyboardFrame.Height - offsetFromBottom + responder.Frame.Height);
                }
            }

            if ((KeyboardChanged != null) && ((neededOffset > 0) || !visible))
            {
                if (isSubview)
                {
                    parentView.Transform = CoreGraphics.CGAffineTransform.MakeTranslation(0, -neededOffset);
                }
                else
                {
                    KeyboardChanged(this, new KeyboardHelperEventArgs(visible, (float)keyboardFrame.Height, neededOffset));
                }
            }
        }
Esempio n. 15
0
        private void KeyBoardUpNotification(NSNotification notifi)
        {
            _keyboardBounds = UIKeyboard.BoundsFromNotification(notifi);

            UpdateElementSize();
        }
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            if (!Utility.IsIPad)
            {
                obs1 = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.DidShowNotification, delegate(NSNotification n)
                {
                    if (isKeyboardVisible && isOptionVisible)
                    {
                        var kbdRect  = UIKeyboard.FrameEndFromNotification(n);
                        var duration = UIKeyboard.AnimationDurationFromNotification(n);
                        var frame    = optionView.Frame;
                        frame.Y      = 66;
                        frame.Height = this.View.Frame.Height - kbdRect.Height;
                        UIView.BeginAnimations("ResizeForKeyboard");
                        UIView.SetAnimationDuration(duration);
                        optionView.Frame = frame;
                        UIView.CommitAnimations();

                        isKeyboardVisible = false;
                        isOptionsKeyboard = true;
                    }
                });

                obs2 = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, delegate(NSNotification n)
                {
                    if (isOptionsKeyboard && isOptionVisible)
                    {
                        var duration = UIKeyboard.AnimationDurationFromNotification(n);

                        UIView.BeginAnimations("ResizeForKeyboard");
                        UIView.SetAnimationDuration(duration);
                        optionView.Frame = new CGRect(0, this.View.Bounds.Height - this.View.Bounds.Height / 1.5, this.View.Bounds.Width, this.View.Bounds.Height / 1.5);
                        UIView.CommitAnimations();

                        isKeyboardVisible = true;
                        isOptionsKeyboard = false;
                    }
                });
            }

            if (indexPath != null)
            {
                var cell = collectionView.CellForItem(indexPath);

                if (cell != null)
                {
                    deselectedButton  = (UIButton)cell.ViewWithTag(500);
                    deselectedButtonX = (UIButton)cell.ViewWithTag(510);
                }
                collectionView.SelectItem(indexPath, true, UICollectionViewScrollPosition.CenteredHorizontally);
            }

            if (!codeVisited)
            {
                UIView.Animate(0.5, 0, UIViewAnimationOptions.CurveLinear, () =>
                {
                    overlayTags.Alpha = 1.0f;
                },
                               () =>
                {
                    UIView.Animate(3.0, () =>
                    {
                        overlayTags.Alpha = 0.0f;
                    });
                }
                               );
            }
        }
        private void KeyboardUpNotification(NSNotification notification)
        {
            var keyboardFrame = UIKeyboard.BoundsFromNotification(notification);

            entryEffect.OnKeyboardRectChanged(new Rect(keyboardFrame.X, keyboardFrame.Y, keyboardFrame.Width, keyboardFrame.Height));
        }
Esempio n. 18
0
        void PositionHUD(NSNotification notification)
        {
            nfloat keyboardHeight    = 0;
            double animationDuration = 0;

            Frame = UIScreen.MainScreen.Bounds;

            UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;
            bool ignoreOrientation             = UIDevice.CurrentDevice.CheckSystemVersion(8, 0);

            if (notification != null)
            {
                var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
                animationDuration = UIKeyboard.AnimationDurationFromNotification(notification);

                if (notification.Name == UIKeyboard.WillShowNotification || notification.Name == UIKeyboard.DidShowNotification)
                {
                    if (ignoreOrientation || IsPortrait(orientation))
                    {
                        keyboardHeight = keyboardFrame.Size.Height;
                    }
                    else
                    {
                        keyboardHeight = keyboardFrame.Size.Width;
                    }
                }
                else
                {
                    keyboardHeight = 0;
                }
            }
            else
            {
                keyboardHeight = VisibleKeyboardHeight;
            }

            CGRect orientationFrame = this.Window.Bounds;
            CGRect statusBarFrame   = UIApplication.SharedApplication.StatusBarFrame;

            if (!ignoreOrientation && IsLandscape(orientation))
            {
                orientationFrame.Size = new CGSize(orientationFrame.Size.Height, orientationFrame.Size.Width);
                statusBarFrame.Size   = new CGSize(statusBarFrame.Size.Height, statusBarFrame.Size.Width);
            }

            var activeHeight = orientationFrame.Size.Height;

            if (keyboardHeight > 0)
            {
                activeHeight += statusBarFrame.Size.Height * 2;
            }

            activeHeight -= keyboardHeight;
            nfloat posY       = (float)Math.Floor(activeHeight * 0.45);
            nfloat posX       = orientationFrame.Size.Width / 2;
            nfloat textHeight = _stringLabel.Frame.Height / 2 + 40;

            switch (toastPosition)
            {
            case ToastPosition.Bottom:
                posY = activeHeight - textHeight;
                break;

            case ToastPosition.Center:
                // Already set above
                break;

            case ToastPosition.Top:
                posY = textHeight;
                break;

            default:
                break;
            }

            CGPoint newCenter;
            float   rotateAngle;

            if (ignoreOrientation)
            {
                rotateAngle = 0.0f;
                newCenter   = new CGPoint(posX, posY);
            }
            else
            {
                switch (orientation)
                {
                case UIInterfaceOrientation.PortraitUpsideDown:
                    rotateAngle = (float)Math.PI;
                    newCenter   = new CGPoint(posX, orientationFrame.Size.Height - posY);
                    break;

                case UIInterfaceOrientation.LandscapeLeft:
                    rotateAngle = (float)(-Math.PI / 2.0f);
                    newCenter   = new CGPoint(posY, posX);
                    break;

                case UIInterfaceOrientation.LandscapeRight:
                    rotateAngle = (float)(Math.PI / 2.0f);
                    newCenter   = new CGPoint(orientationFrame.Size.Height - posY, posX);
                    break;

                default:                         // as UIInterfaceOrientationPortrait
                    rotateAngle = 0.0f;
                    newCenter   = new CGPoint(posX, posY);
                    break;
                }
            }

            if (notification != null)
            {
                UIView.Animate(animationDuration,
                               0, UIViewAnimationOptions.AllowUserInteraction, delegate
                {
                    MoveToPoint(newCenter, rotateAngle);
                }, null);
            }
            else
            {
                MoveToPoint(newCenter, rotateAngle);
            }
        }
 void HandleKeyboardState(NSNotification notification)
 {
     keyboardBounds = UIKeyboard.BoundsFromNotification(notification);
     View.Center    = new CGPoint(View.Bounds.GetMidX(), View.Bounds.GetMidY() - keyboardBounds.Height);
     SetViewMovedUp(!keyboardBounds.IsEmpty);
 }
Esempio n. 20
0
        private void KeyboardDidShow(NSNotification notification)
        {
            var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);

            KeyboardWillChange(keyboardFrame.Height, notification);
        }
Esempio n. 21
0
        protected virtual void KeyboardWillShowNotification(NSNotification notification)
        {
            UIView activeView = KeyboardGetActiveView();

            if (activeView == null)
            {
                return;
            }

            CGRect keyboardBounds = UIKeyboard.FrameBeginFromNotification(notification);

            if (scrollType == ScrollType.SCROLLVIEW)
            {
                UIScrollView scrollView = activeView.FindSuperviewOfType(parentView, typeof(UIScrollView)) as UIScrollView;
                if (scrollView == null)
                {
                    return;
                }

                nfloat keyboardHeight;
                if (keyboardBounds.Size.Height > keyboardBounds.Size.Width)
                {
                    keyboardHeight = keyboardBounds.Size.Width;
                }
                else
                {
                    keyboardHeight = keyboardBounds.Size.Height;
                }

                UIEdgeInsets contentInsets = new UIEdgeInsets(0.0f, 0.0f, keyboardHeight, 0.0f);
                scrollView.ContentInset          = contentInsets;
                scrollView.ScrollIndicatorInsets = contentInsets;

                // If activeField is hidden by keyboard, scroll it so it's visible
                CGRect viewRectAboveKeyboard = new CGRect(parentView.Frame.Location, new CGSize(parentView.Frame.Width, parentView.Frame.Size.Height - keyboardHeight));

                // activeFieldAbsoluteFrame is relative to this.View so does not include any scrollView.ContentOffset
                CGRect activeFieldAbsoluteFrame = activeView.Superview.ConvertRectToView(activeView.Frame, parentView);

                // Check if the activeField will be partially or entirely covered by the keyboard
                if (!viewRectAboveKeyboard.Contains(activeFieldAbsoluteFrame))
                {
                    // Scroll to the activeField Y position + activeField.Height + current scrollView.ContentOffset.Y - the keyboard Height
                    CGPoint scrollPoint = new CGPoint(0.0f, activeFieldAbsoluteFrame.Location.Y + activeFieldAbsoluteFrame.Height + scrollView.ContentOffset.Y - viewRectAboveKeyboard.Height);
                    scrollView.SetContentOffset(scrollPoint, true);
                }
            }
            else if (scrollType == ScrollType.TABLEVIEW)
            {
                UITableView tableView = activeView.FindSuperviewOfType(parentView, typeof(UITableView)) as UITableView;
                if (tableView == null)
                {
                    return;
                }

                nfloat keyboardHeight;
                if (keyboardBounds.Size.Height > keyboardBounds.Size.Width)
                {
                    keyboardHeight = keyboardBounds.Size.Width;
                }
                else
                {
                    keyboardHeight = keyboardBounds.Size.Height;
                }

                UIEdgeInsets contentInsets = new UIEdgeInsets(0.0f, 0.0f, keyboardHeight, 0.0f);
                tableView.ContentInset          = contentInsets;
                tableView.ScrollIndicatorInsets = contentInsets;

                // If activeField is hidden by keyboard, scroll it so it's visible
                CGRect viewRectAboveKeyboard = new CGRect(parentView.Frame.Location, new CGSize(parentView.Frame.Width, parentView.Frame.Size.Height - keyboardHeight));

                // activeFieldAbsoluteFrame is relative to this.View so does not include any tableView.ContentOffset
                CGRect activeFieldAbsoluteFrame = activeView.Superview.ConvertRectToView(activeView.Frame, parentView);

                // Check if the activeField will be partially or entirely covered by the keyboard
                if (!viewRectAboveKeyboard.Contains(activeFieldAbsoluteFrame))
                {
                    // Scroll to the activeField Y position + activeField.Height + current tableView.ContentOffset.Y - the keyboard Height
                    CGPoint scrollPoint = new CGPoint(0.0f, activeFieldAbsoluteFrame.Location.Y + activeFieldAbsoluteFrame.Height + tableView.ContentOffset.Y - viewRectAboveKeyboard.Height);
                    tableView.SetContentOffset(scrollPoint, true);
                }
            }
            else if (scrollType == ScrollType.TEXTVIEW)
            {
                UITextView textView = activeView as UITextView;
                if (textView == null)
                {
                    return;
                }

                nfloat keyboardHeight;
                if (keyboardBounds.Size.Height > keyboardBounds.Size.Width)
                {
                    keyboardHeight = keyboardBounds.Size.Width;
                }
                else
                {
                    keyboardHeight = keyboardBounds.Size.Height;
                }

                UIEdgeInsets contentInsets = new UIEdgeInsets(0.0f, 0.0f, keyboardHeight, 0.0f);
                textView.ContentInset          = contentInsets;
                textView.ScrollIndicatorInsets = contentInsets;

                // If activeField is hidden by keyboard, scroll it so it's visible
                CGRect viewRectAboveKeyboard = new CGRect(parentView.Frame.Location, new CGSize(parentView.Frame.Width, parentView.Frame.Size.Height - keyboardHeight));

                // activeFieldAbsoluteFrame is relative to this.View so does not include any tableView.ContentOffset
                CGRect activeFieldAbsoluteFrame = activeView.Superview.ConvertRectToView(activeView.Frame, parentView);

                // Check if the activeField will be partially or entirely covered by the keyboard
                if (!viewRectAboveKeyboard.Contains(activeFieldAbsoluteFrame))
                {
                    // Scroll to the activeField Y position + activeField.Height + current tableView.ContentOffset.Y - the keyboard Height
                    CGPoint scrollPoint = new CGPoint(0.0f, activeFieldAbsoluteFrame.Location.Y + activeFieldAbsoluteFrame.Height + textView.ContentOffset.Y - viewRectAboveKeyboard.Height);
                    textView.SetContentOffset(scrollPoint, true);
                }
            }

            if (KeyboardWillShowEvent != null)
            {
                KeyboardWillShowEvent(keyboardBounds);
            }
        }