// // ShakeLabel2.m // BuguLive // // Created by xfg on 16/5/23. // Copyright © 2016年 xfg. All rights reserved. // #import "ShakeLabel2.h" @implementation ShakeLabel2 - (void)startAnimWithDuration:(NSTimeInterval)duration { __weak ShakeLabel2 *ws = self; [UIView animateKeyframesWithDuration:duration delay:0 options:0 animations:^{ [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1/2.0 animations:^{ self.transform = CGAffineTransformMakeScale(5, 5); }]; [UIView addKeyframeWithRelativeStartTime:1/2.0 relativeDuration:1/2.0 animations:^{ self.transform = CGAffineTransformMakeScale(0.7, 0.7); }]; } completion:^(BOOL finished) { [UIView animateWithDuration:0.25 delay:0 usingSpringWithDamping:0.4 initialSpringVelocity:10 options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.transform = CGAffineTransformMakeScale(1.0, 1.0); } completion:^(BOOL finished) { if (ws.delegate && [ws.delegate respondsToSelector:@selector(shakeLabelAnimateFinished2)]) { [ws.delegate shakeLabelAnimateFinished2]; } }]; }]; } // 重写 drawTextInRect 文字描边效果 - (void)drawTextInRect:(CGRect)rect { CGSize shadowOffset = self.shadowOffset; UIColor *textColor = self.textColor; CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(c, 2); CGContextSetLineJoin(c, kCGLineJoinRound); CGContextSetTextDrawingMode(c, kCGTextStroke); self.textColor = _borderColor; [super drawTextInRect:rect]; CGContextSetTextDrawingMode(c, kCGTextFill); self.textColor = textColor; self.shadowOffset = CGSizeMake(0, 0); [super drawTextInRect:rect]; self.shadowOffset = shadowOffset; } @end