Пример #1
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();
        }
Пример #2
0
        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;
            });
        }
Пример #3
0
        /// <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();
        }
Пример #4
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();
        }
Пример #5
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();
        }
Пример #6
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);
            }
        }
Пример #7
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);
        }
        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
                );
        }
        // 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();
        }
Пример #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);
            }
        }
Пример #12
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.
            });
        }
Пример #13
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);
            });
        }
        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();
            }
        }