Пользовательский TabbedRenderer - вкладка сверху на iOS - PullRequest
0 голосов
/ 15 ноября 2018

Я делаю CustomTabbedRenderer, чтобы установить панель вкладок в верхней части страницы на iOS.Эти TopTabbedBar вложены как вкладка корневой вкладки.

Сначала я получаю то, что хочу (см. Изображение): правильный макет Но когда я выбираю другую вкладку, Page.ContainerAreaизменить размер (см. изображение), и coontrol находится за панелью вкладок. плохой макет

public class TabbedPageCustomRenderer : TabbedRenderer
{
        bool _loaded;
        Size _queuedSize;



        Page Page => Element as Page;


        public override void ViewDidLayoutSubviews()
        {
            base.ViewDidLayoutSubviews();

            if (Element == null)
                return;

            if (!Element.Bounds.IsEmpty)
            {   
        // I add "(loat)10" to shift the View.Frame under the statusbar

                View.Frame = new System.Drawing.RectangleF((float)Element.X, (float)10, (float)Element.Width, (float)(Element.Height-10));
            }

            var tabBarFrame = TabBar.Frame;

            var frame = ParentViewController != null ? ParentViewController.View.Frame : View.Frame;
            var height = frame.Height - tabBarFrame.Height;

        // I add "tabBarFrame.Height" to shift the "Page.ContainerArea" under the Tabbar
            Page.ContainerArea = new Rectangle(0, tabBarFrame.Height, frame.Width, height);


            if (!_queuedSize.IsZero)
            {
                Element.Layout(new Rectangle(Element.X, Element.Y, _queuedSize.Width, _queuedSize.Height));
                _queuedSize = Size.Zero;
            }

            _loaded = true;
        }

        public override void ViewWillLayoutSubviews()
        {
            base.ViewWillLayoutSubviews();
            this.TabBar.InvalidateIntrinsicContentSize();


            nfloat tabSize = 44.0f;

            UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;

            if (UIInterfaceOrientation.LandscapeLeft == orientation || UIInterfaceOrientation.LandscapeRight == orientation)
            {
                tabSize = 32.0f;
            }

            var tabFrame = this.TabBar.Frame;
            tabFrame.Height = tabSize;
            tabFrame.Y = View.Frame.Y;
            this.TabBar.Frame = tabFrame;

            //this.TabBar.TopAnchor = false;
            this.TabBar.Translucent = false;
            this.TabBar.Translucent = true;
        }
    }

При нажатии на новую вкладку я обнаруживаю, что "SafeAreaInsets" сброшен.Может быть, это проблема.

Можете ли вы помочь мне, пожалуйста.

...