Skip to content

Instantly share code, notes, and snippets.

@JonFir
Created January 20, 2018 06:48
Show Gist options
  • Save JonFir/1691d6e9ea82e1b1f0727f48db2e097e to your computer and use it in GitHub Desktop.
Save JonFir/1691d6e9ea82e1b1f0727f48db2e097e to your computer and use it in GitHub Desktop.
/**
Слой с иконкой
*/
@property (weak, nonatomic) CAShapeLayer *iconLayer;
@end
@implementation YTSSuccessIconView
- (instancetype)init
{
self = [super init];
if (self) {
_iconColor = [UIColor whiteColor];
_lineWidth = 10.0f;
}
return self;
}
/**
Отрисовать и показать иконку
*/
- (void)drawIcon
{
[self.iconLayer removeFromSuperlayer];
CAShapeLayer *iconLayer = [CAShapeLayer layer];
iconLayer.frame = self.bounds;
iconLayer.path = [self makeIconPath];
iconLayer.strokeColor = self.iconColor.CGColor;
iconLayer.fillColor = NULL;
iconLayer.lineWidth = self.lineWidth;
iconLayer.lineCap = kCALineCapRound;
iconLayer.lineJoin = kCALineJoinRound;
[self.layer addSublayer:iconLayer];
self.iconLayer = iconLayer;
}
/**
Фабричный метод для поучения кривой иконки
@return кривая иконки
*/
- (CGPathRef)makeIconPath
{
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint: [self proportionalPointInX:0.03371
andY:0.52951]];
[path addLineToPoint: [self proportionalPointInX:0.33074
andY:0.95200]];
[path addLineToPoint: [self proportionalPointInX:0.96629
andY:0.04800]];
return path.CGPath;
}
/**
Собирает и показывает иконку с анимацией
@param animation группа анимаций для отображения иконки
*/
- (void)drawIconWithAnimation:(CAAnimationGroup *)animation
{
[self drawIcon];
[self.iconLayer addAnimation:animation forKey:nil];
}
- (void)clearIcon
{
[self.iconLayer removeFromSuperlayer];
}
/**
Создает точку учитывая пропорции иконки
*/
- (CGPoint)proportionalPointInX:(CGFloat)x
andY:(CGFloat)y
{
const CGFloat proportionalX = CGRectGetMinX(self.bounds) + x * self.bounds.size.width;
const CGFloat proportionalY = CGRectGetMinY(self.bounds) + y * self.bounds.size.height;
return CGPointMake(proportionalX, proportionalY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment