wxr
2020-03-05 0bdc0a135dbe31761b53f432ed34f347f0a4e36b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System;
using UIKit;
using CoreAnimation;
 
 
namespace Shared
{
    /// <summary>
    /// 当前视图
    /// </summary>
    public class Spinner : Button
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        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();
                }
            });
 
        }
 
        /// <summary>
        /// 刷新当前视图
        /// </summary>
        public override void Refresh()
        {
            base.Refresh();
            CurrentRow = currentRow;
        }
            
 
 
        int currentRow;
        /// <summary>
        /// 
        /// </summary>
        /// <value>The current row.</value>
        public int CurrentRow
        {
            get
            {
                return currentRow;
 
            }
            set
            {
                if (AdapterStr == null || value < 0 || AdapterStr.Length <= value)
                {
                    return;
                }
 
                currentRow = value;
                Text = AdapterStr[value];
            }
        }
    
 
        /// <summary>
        /// 添加下拉列表的数据
        /// </summary>
        /// <param name="Str">String.</param>
        public string []AdapterStr {
            get;
            set ;
        }
 
        /// <summary>
        /// 选择列表变化的事件
        /// </summary>
         public Action<View, int> SelectedItemChanged;
 
    }
 
 
}