Пример #1
0
        internal void MakeVisible(NSView view, BringIntoViewMode?bringIntoViewMode, bool useForcedAnimation = false)
        {
            if (view == null)
            {
                return;
            }

            if (bringIntoViewMode == null)
            {
                return;
            }

            var scrollView = view.FindSuperviewsOfType <NSScrollView>().LastOrDefault();

            _scrollViewModifiedForKeyboard = new WeakReference <NSScrollView>(scrollView);

            if (scrollView == null)
            {
                this.Log().Warn("Keyboard will show, but we cannot find any ScrollView with enough space for the currently focused view, so it's impossible to ensure that it's visible.");
                return;
            }


            var scrollViewRectInWindow = scrollView.ConvertRectFromView(scrollView.Bounds, scrollView);

            var keyboardTop = (nfloat)_inputPane.OccludedRect.Top;

            var keyboardOverlap = scrollViewRectInWindow.Bottom - keyboardTop;

            if (keyboardOverlap > 0)
            {
                scrollView.ContentInsets = new NSEdgeInsets(0, 0, keyboardOverlap, 0);
            }

            var viewRectInScrollView = CGRect.Empty;

            if (!(view is TextBox))
            {
                // We want to scroll to the textbox and not the inner textview.
                view = view.FindFirstParent <TextBox>() ?? view;
            }

            viewRectInScrollView = scrollView.ConvertRectFromView(view.Bounds, view);

            scrollView.ScrollRectToVisible(viewRectInScrollView);
        }