using System; using UIKit; using CoreAnimation; namespace Shared { /// /// 当前视图 /// public class Spinner : Button { /// /// 构造函数 /// public Spinner () { TextColor = 0xff007aff; BorderWidth = 1; Radius = 10; MouseUpEventHandler += (sender1, e1) => { if (AdapterStr == null || AdapterStr.Length == 0) { return; } UIScrollView tempUIScrollView = new UIScrollView(); tempUIScrollView.BackgroundColor = UIColor.Clear; var frame2 = tempUIScrollView.Frame; frame2.Width = Application.CurrentWidth; frame2.Height = Application.CurrentHeight; tempUIScrollView.Frame = frame2; tempUIScrollView.Alpha = 0.94f; UITapGestureRecognizer gestureRecognizer = new UITapGestureRecognizer(() => { remoteFromSuperview(tempUIScrollView); }); tempUIScrollView.AddGestureRecognizer(gestureRecognizer); int height = 40; var size = tempUIScrollView.ContentSize; size.Width = Application.CurrentWidth; size.Height = height * AdapterStr.Length; tempUIScrollView.ContentSize = size; size.Width = 20; size.Height = 20; for (int i = 0; i < AdapterStr.Length; i++) { UIButton button = new UIButton(); var tempButtonFrame = button.Frame; tempButtonFrame.Y = (int)Math.Max(tempUIScrollView.Frame.Height, tempUIScrollView.ContentSize.Height) - (height * (i + 1)); tempButtonFrame.Width = Application.CurrentWidth; tempButtonFrame.Height = height; button.Frame = tempButtonFrame; button.SetTitle(AdapterStr[i], UIControlState.Normal); button.SetTitleColor(new UIColor(0x6d / 255.0f, 0x6d / 255.0f, 0x72 / 255.0f, 1), UIControlState.Normal); button.BackgroundColor = UIColor.White; button.Tag = i; button.TouchUpInside += (sender, ee) => { remoteFromSuperview(tempUIScrollView); Text = AdapterStr[button.Tag]; if (SelectedItemChanged != null) { SelectedItemChanged(this, (int)button.Tag); } }; tempUIScrollView.AddSubview(button); if (i == this.AdapterStr.Length - 1) { UIBezierPath uIBezierPath = UIBezierPath.FromRoundedRect(button.Bounds, UIRectCorner.TopLeft | UIRectCorner.TopRight, size); CAShapeLayer cAShapeLayer = new CAShapeLayer(); cAShapeLayer.Frame = button.Bounds; cAShapeLayer.Path = uIBezierPath.CGPath; button.Layer.Mask = cAShapeLayer; } else { UIView line = new UIView(); var ddd = line.Frame; ddd.Y = button.Frame.Y; ddd.Width = Application.CurrentWidth; ddd.Height = 1; line.Frame = ddd; line.BackgroundColor = new UIColor(0xdd / 255.0f, 0xdd / 255.0f, 0xdd / 255.0f, 1); tempUIScrollView.AddSubview(line); if (i == 0) { UIBezierPath uIBezierPath = UIBezierPath.FromRoundedRect(button.Bounds, UIRectCorner.BottomLeft | UIRectCorner.BottomRight, size); CAShapeLayer cAShapeLayer = new CAShapeLayer(); cAShapeLayer.Frame = button.Bounds; cAShapeLayer.Path = uIBezierPath.CGPath; button.Layer.Mask = cAShapeLayer; } } } var frame = tempUIScrollView.Frame; frame.Y = Application.CurrentHeight; tempUIScrollView.Frame = frame; Application.RootFrameLayout.AddSubview(tempUIScrollView); UIView.AnimateNotify(0.6f, 0.01f, UIViewAnimationOptions.CurveLinear, () => { frame.Y = 0; tempUIScrollView.Frame = frame; }, null); }; } void remoteFromSuperview(UIScrollView uIScrollView) { UIView.AnimateNotify(0.6f,0.01f,UIViewAnimationOptions.CurveLinear,() => { var frame= uIScrollView.Frame ; frame.Y=Application.CurrentHeight; uIScrollView.Frame=frame; },(b)=>{ if(b) { uIScrollView.RemoveFromSuperview(); } }); } /// /// 刷新当前视图 /// public override void Refresh() { base.Refresh(); CurrentRow = currentRow; } int currentRow; /// /// /// /// The current row. public int CurrentRow { get { return currentRow; } set { if (AdapterStr == null || value < 0 || AdapterStr.Length <= value) { return; } currentRow = value; Text = AdapterStr[value]; } } /// /// 添加下拉列表的数据 /// /// String. public string []AdapterStr { get; set ; } /// /// 选择列表变化的事件 /// public Action SelectedItemChanged; } }