黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/ListViewLayoutControls/VerticalListControl.cs
@@ -15,6 +15,29 @@
        /// 行之间的间距
        /// </summary>
        public int rowSpace = 0;
        /// <summary>
        /// 最大高度
        /// </summary>
        private int maxHeight = -1;
        /// <summary>
        /// 一个没什么用的东西
        /// </summary>
        private FrameLayout frameBackTemp = null;
        /// <summary>
        /// 自定义的获取子控件个数
        /// </summary>
        public new int ChildrenCount
        {
            get
            {
                int count = base.ChildrenCount;
                if (frameBackTemp != null && frameBackTemp.Parent != null)
                {
                    count--;
                }
                return count < 0 ? 0 : count;
            }
        }
        #endregion
@@ -26,7 +49,14 @@
        /// <param name="i_rowSpace">行之间的间距(这个值是与行控件绑定一起使用的)</param>
        public VerticalListControl(int i_rowSpace = 0)
        {
            rowSpace = Application.GetRealHeight(i_rowSpace);
            this.rowSpace = Application.GetRealHeight(i_rowSpace);
#if iOS
            //自动偏移取消
            if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                (this.uiView as UIKit.UIScrollView).ContentInsetAdjustmentBehavior = UIKit.UIScrollViewContentInsetAdjustmentBehavior.Never;
            }
#endif
        }
        #endregion
@@ -47,7 +77,134 @@
                    view.Height += rowSpace;
                }
            }
            if (maxHeight == -1)
            {
                maxHeight = this.Height;
            }
        }
        #endregion
        #region ■ 调整真实高度_______________________
        /// <summary>
        /// 还原高度
        /// </summary>
        public void RecoverHeight()
        {
            if (this.maxHeight != -1)
            {
                this.Height = this.maxHeight;
#if iOS
                this.ReLocation();
#endif
            }
        }
        /// <summary>
        /// 调整控件真实高度(只针对行控件都是相同高度的,高度只会减少,不会增加)
        /// </summary>
        /// <param name="bottomSpace">底部空白间距(真实值)</param>
        /// <param name="addSpace">当真实高度超过原有高度时,是否添加空白</param>
        public void AdjustRealHeight(int bottomSpace, bool addSpace = true)
        {
            //总之,先重置至最大
            this.RecoverHeight();
            int count = this.ChildrenCount;
            if (count <= 0)
            {
                frameBackTemp?.RemoveFromParent();
                frameBackTemp = null;
                return;
            }
            //调整列表控件的高度
            var realHeight = count * this.GetChildren(0).Height + bottomSpace;
            if (realHeight < this.Height)
            {
                frameBackTemp?.RemoveFromParent();
                frameBackTemp = null;
                //缩小控件高度
                this.Height = realHeight;
#if iOS
                this.ReLocation();
#endif
            }
            else if (addSpace == true && bottomSpace > 0 && realHeight > this.maxHeight)
            {
                frameBackTemp?.RemoveFromParent();
                frameBackTemp = new FrameLayout();
                frameBackTemp.Height = bottomSpace;
                this.AddChidren(frameBackTemp);
            }
        }
        /// <summary>
        /// 针对底部点击按钮,调整控件真实高度
        /// </summary>
        /// <param name="bottomSpace">底部空白间距(真实值,如果列表控件真实高度没有超过时,使用此值)</param>
        /// <param name="correctionsValue">Y轴补正值(真实值,列表控件不在bodyFramelayout的时候使用)</param>
        public void AdjustRealHeightByBottomButton(int bottomSpace, int correctionsValue = 0)
        {
            if (this.ChildrenCount == 0)
            {
                frameBackTemp?.RemoveFromParent();
                frameBackTemp = null;
                if (maxHeight != -1)
                {
                    //还原为最大高度
                    this.Height = maxHeight;
#if iOS
                    this.ReLocation();
#endif
                }
                return;
            }
            var realHeight = this.ChildrenCount * this.GetChildren(0).Height + this.Y + correctionsValue;
            var btnTemp = new BottomClickButton();
            if (btnTemp.Yaxis >= realHeight)
            {
                //没有超过
                this.AdjustRealHeight(bottomSpace);
                return;
            }
            //超过时,重置至最大
            this.RecoverHeight();
            //添加临时控件,直至可以滑动超过底部按钮
            frameBackTemp?.RemoveFromParent();
            frameBackTemp = new FrameLayout();
            frameBackTemp.Height = ControlCommonResourse.BodyFrameHeight - btnTemp.Yaxis + bottomSpace;
            this.AddChidren(frameBackTemp);
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 控件移除
        /// </summary>
        public override void RemoveFromParent()
        {
            if (this.Parent != null)
            {
                base.RemoveFromParent();
            }
        }
        /// <summary>
        /// ☆☆移除全部控件☆☆
        /// </summary>
        public override void RemoveAll()
        {
            if (this.Parent != null)
            {
                base.RemoveAll();
            }
        }
        #endregion
    }
}