一天一工程总结系列-7.2

2015
7.2
一天一工程总结系列
对各类优秀工程的剖析和拙见。有些胡言乱语还请作者谅解。

VBFPopFlatButton
1.执行多次的单例
#define AGEColorImplement(COLOR_NAME,RED,GREEN,BLUE)    \
+ (UIColor *)COLOR_NAME{    \
    static UIColor* COLOR_NAME##_color;    \
    static dispatch_once_t COLOR_NAME##_onceToken;   \
    dispatch_once(&COLOR_NAME##_onceToken, ^{    \
        COLOR_NAME##_color = [UIColor colorWithRed:RED green:GREEN blue:BLUE alpha:1.0];  \
        NSLog(@"1");\
    }); \
    return COLOR_NAME##_color;  \
}\

有个牛人对dispatch_once的代码级解析:http://blog.csdn.net/uxyheaven/article/details/24735237

这样的写法来自http://blog.alexedge.co.uk/speeding-up-uicolor-categories/

2.VBFPopFlatButton

继承自UIButton。

VBFPopFlatButton有一个NSInteger类型的枚举FlatButtonType,对应Demo里的各种按钮样式。

另外含有三个VBFDoubleSegment的实例变量,firstSegment,secondSegment,thirdSegment.

关键函数

-(void)animateToTyle:(FlatButtonType)finalTyle

{

     [self.xxSegment moveToState:xxxx animated:self.animateToStartPosition];

    [self addSpringRotationToLayer:self.topLine toValue:toValueTop];

                   POPSpringAnimation anim.toValue = @(toValue);

    self.xxLine.transform = CATransform3DMakeRotation(toValueTop,,,);

     [self.xxSegment movePositionToPoint:xxxOriginPoint animated:self.animateToStartPosition];

            [self addSpringTranslationToLayer:self.topLine toValue:toPoint];

                    POPSpringAnimation anim.toValue = @(toValue);

            self.xxLine.position = finalPosition

}

3.@interface VBFDoubleSegment:CALayer

有一个NSInteger类型的DoubleSegmentState枚举,每一个枚举对应一个按钮样式。

包含两个成员,topLine/bottomLine,两者均是CAShapeLayer的实例变量。这两个layer,用addsubLayer的方式加在VBFDoubleSegment上。

4.动画效果,由第三方类pop实现。

posted @ 2015-07-02 17:36  magicya  阅读(93)  评论(0编辑  收藏  举报