码迷,mamicode.com
首页 > 其他好文 > 详细

BottomNavigationBarXF 自动隐藏

时间:2017-09-26 21:15:51      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:message   property   hang   ons   支持   logs   creat   can   value   

目前,BottomNavigationBarXF 好像不支持 CoordinatorLayout 布局(BottomNavigationBar是支持的)。可以用以下比较迂回的方法实现BottomBar的自动隐藏:

1、Touch响应。

以自定义WebView为例:

在HybridWebViewRenderer中添加方法:

//...
protected override void OnElementChanged(ElementChangedEventArgs<HybridWebView> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
            {
                //...
            }
//...
            Control.Touch += Control_Touch;
//...
      }

        float _startEventY;
        float _heightChange;
        private void Control_Touch(object sender, TouchEventArgs e)
        {
            var ev = e.Event;
            MotionEventActions action = ev.Action & MotionEventActions.Mask;
            switch (action)
            {
                case MotionEventActions.Down:
                    _startEventY = ev.GetY();
                    _heightChange = 0;
                    break;
                case MotionEventActions.Move:
                    float delta = (ev.GetY() + _heightChange) - _startEventY;
                    Element.TouchScroll(delta);
                    /*
                    var callDialog = new AlertDialog.Builder((Activity)Forms.Context);
                    callDialog.SetMessage(String.Format("scrolling delta is {0}, change {1}, start {2}", delta, _heightChange, _startEventY));
                    callDialog.SetNegativeButton("Cancel", delegate { });
                    callDialog.Show();
                    */
                    break;
            }
            e.Handled = false;
        }
//...

在HybridWebViewPage中:

  //...
       public HybridWebViewPage(Uri uri)
        {
            InitializeComponent();
            //...
            hybridWebView.TouchScroll += WebViewPage_TouchScroll;
        }
        //...
        private void WebViewPage_TouchScroll(float moved)
        {
            if (moved < -60)
            {
                App.tabbedPage.BarHide?.Invoke(true);
            }
            else if (moved > 60)
            {
                App.tabbedPage.BarHide?.Invoke(false);
            }
        }
  //...

2、添加BarHide属性:

BottomBarPage中添加BarHide:

    public class BottomBarPage : TabbedPage
    {
        public enum BarThemeTypes { Light, DarkWithAlpha, DarkWithoutAlpha }

        public bool FixedMode { get; set; }

        public BarThemeTypes BarTheme { get; set; }
        /**/
        public static BindableProperty BarHideProperty = BindableProperty.Create(nameof(BarHide), typeof(Action<bool>), typeof(BottomBarPage), null, BindingMode.OneWayToSource);
        public Action<bool> BarHide
        {
            get { return (Action<bool>)GetValue(BarHideProperty); }
            set { SetValue(BarHideProperty, value); }
        }
        public void RaiseCurrentPageChanged()
        {
            OnCurrentPageChanged();
        }
    }

BottomBarPageRenderer中:

        protected override void OnElementChanged(ElementChangedEventArgs<BottomBarPage> e)
        {
            base.OnElementChanged(e);
            if (e.NewElement != null)
            {
//...
                Element.BarHide = (isHide) =>
                {
                    if (isHide)
                    {
                        _bottomBar.Hide(false);
                    }
                    else
                    {
                        _bottomBar.Show(false);
                    }
                };
//...
                _bottomBar.BarDidHide = (sender, evts) => {
                    _bottomBar.TranslationY = 0;
                };
//...
            }
        }

 

BottomNavigationBarXF 自动隐藏

标签:message   property   hang   ons   支持   logs   creat   can   value   

原文地址:http://www.cnblogs.com/arkoo/p/7598432.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!