SCLAlertViewSCLAlertView: Beautiful animated Alert View. Swift version. 它是继承自 UIViewController,而不是UIView。 逻辑整理上面的圆圈图标由 circleViewBackground -> circleView -> circleIconImageView 层级构成,由 layer.cornerRadius 指定它们的圆圈角度。 最下层全屏幕显示的背景 backgroundView 有三种样式,阴影、模糊(由苹果 UIImage+ImageEffects 文件处理)、透明。 alertView 需要展示内容添加到 contentView 上,用一个数组 customViews 来装这些自定义的 view,目的是为了调整 alertview 的 frame。 而 textfield 则是用 inputs 数组来装,要让不是最后一个的 textfield.returnKeyType 为 UIReturnKeyNext,这样用户点击键盘上的完成后,焦点自动定位到下一个 textfield。 并且在 textFieldShouldReturn: 代理里面 becomeFirstResponder 弹出键盘。 它的显示方式有两种,一种是显示在某个 parentViewController 上(addChildViewController ,另外一种就是添加到自定义的 Window 上(设置 windowLevel、rootViewController)。 知识点- 链式语法;
- UIView 动画的使用;
- tintColor 知识点;
- UIWindow 简易知识点;
- UIControl sendAction: ;
- UIBezierPath 画图;
T. m# T M& u 链式语法block 要玩的比较溜,. w6 q+ o+ s! N
- @property(copy, nonatomic) SCLAlertViewBuilder *(^cornerRadius) (CGFloat cornerRadius);; E) B3 P! N* i' W+ u
- - (SCLAlertViewBuilder *(^) (CGFloat cornerRadius))cornerRadius {
2 W! Y$ N5 _: h: x - if (!_cornerRadius) {9 v5 d2 i/ l* D' g3 C
- __weak typeof(self) weakSelf = self; d8 m# L- E) R- F' v4 n7 Y
- _cornerRadius = ^(CGFloat cornerRadius) {3 u* A* O" `$ @7 U' F6 X
- weakSelf.alertView.cornerRadius = cornerRadius;
& K. E/ V2 h: @8 f3 u6 ^) ` - return weakSelf;0 P" M- g2 |& H m( q" u
- };
4 `& O: I7 @+ R b2 x- f - }
6 ~# z" N7 T$ p - return _cornerRadius;
' c; z- P, H4 k* a - }
& {2 [. y# d- d7 i - // 由于上面的属性名和入参名一样 所以我把入参名改为 value 了。. v0 Z6 u- b; o% q* D+ B
- @property(copy, nonatomic) SCLAlertViewBuilder *(^cornerRadius) (CGFloat value);$ C3 G2 v1 {" T
- - (SCLAlertViewBuilder *(^) (CGFloat value))cornerRadius {
& x+ }1 B+ c |: z9 R, U3 W, s - if (!_cornerRadius) {: w& A) a7 Q& b
- __weak typeof(self) weakSelf = self;4 {( P8 G1 j; U
- _cornerRadius = ^(CGFloat value) {3 o0 S$ h$ p' k: J4 c
- weakSelf.alertView.cornerRadius = value;
5 d% C2 \0 T) g& ^ - return weakSelf;
+ X* `& n: n2 c2 P+ y7 w - };9 [. f" ^8 A" r/ h
- }
! G$ H* I8 { O1 S. v5 w: h - return _cornerRadius;8 |, i0 S/ I+ a- B" Y) W
- }
复制代码 * }6 N0 s% I9 z$ s- E9 y. Z
该 block 的返回值类型就是自己,入参就是你要设置的属性。本来想写个 UIView 的相关设置来练下手的,结果发现已经有人写了。 UIView 动画的使用根据 SCLAlertViewShowAnimation 和 SCLAlertViewHideAnimation 来调用不同的动画,而这个动画都是由 UIView 的类方法完成的。 tintColor 知识点tintColor 永远会返回一个 color 值(默认为 UIDeviceRGBColorSpace 0 0.478431 1 1)。当父视图的 tintColor 发生改变时,它所有的子视图的 tintColor 也会跟着发生改变。我们可以重载 tintColorDidChange 发生来监听 color 的改变,来调整自身的颜色。 UIWindow 简易知识点windowLevel、rootViewController、makeKeyAndVisible 等。 UIControl sendAction:事件的传递。 UIBezierPath 画图在 SCLAlertViewStyleKit 类里面,用 UIBezierPath 画 SCLAlertViewStyle 各种类型所代码的图片。 ! q! v2 ]' s. \0 W% O' L$ k
|