123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- //
- // FKPaySuccessAnimView.m
- // FirstLink
- //
- // Created by jack on 15/9/16.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "FKPaySuccessAnimView.h"
- @interface FKPaySuccessAnimView ()
- //@property (nonatomic, weak) id delegate;
- @property (nonatomic, strong) CAShapeLayer *animLayer;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, copy) void(^finish)(BOOL done);
- @end
- @implementation FKPaySuccessAnimView
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- [self addAllSubViews];
- }
- return self;
- }
- - (void)addAllSubViews{
-
- [self.layer addSublayer:self.animLayer];
- [self addSubview:self.titleLabel];
- }
- + (void)showInView:(UIView *)view finish:(void(^)(BOOL done))finish{
-
- for (UIView *subView in view.subviews) {
- if ([subView isKindOfClass:[FKPaySuccessAnimView class]]){
- [subView removeFromSuperview];
- }
- }
-
- CGPoint center = [view convertPoint:view.window.center fromView:view.window];
- FKPaySuccessAnimView *animView = [[FKPaySuccessAnimView alloc]init];
- [view addSubview:animView];
-
- animView.bounds = CGRectMake(0, 0, 200, 130);
- animView.center = center;
- animView.finish = finish;
-
- [animView startAnimatrion];
- }
- - (void)startAnimatrion{
-
- CABasicAnimation *tailAnimation = [CABasicAnimation animation];
- tailAnimation.keyPath = @"strokeEnd";
- tailAnimation.duration = 1.f;
- tailAnimation.fromValue = @(0.f);
- tailAnimation.toValue = @(1.f);
- tailAnimation.timingFunction = [CAMediaTimingFunction functionWithName:@"easeOut"];
- tailAnimation.delegate = self;
-
- [self.animLayer addAnimation:tailAnimation forKey:nil];
-
- }
- - (void)layoutSubviews{
- [super layoutSubviews];
-
- self.titleLabel.bounds = CGRectMake(0, 0, CGRectGetWidth(self.bounds), 30);
- self.titleLabel.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMaxY(self.bounds) - 30);
- self.animLayer.bounds = self.bounds;
- self.animLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
-
- [self configPath];
- }
- - (void)configPath{
-
- CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), 45);
- CGFloat radius = 30;
- CGFloat startAngle = (CGFloat)(M_PI);
- CGFloat endAngle = (CGFloat)(3*M_PI + M_PI_4);
- UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
-
- CGPoint point1 = CGPointMake(CGRectGetMidX(self.bounds) - 17, 48);
- CGPoint point2 = CGPointMake(CGRectGetMidX(self.bounds) - 5, 60);
- CGPoint point3 = CGPointMake(CGRectGetMidX(self.bounds) + 20, 37);
-
- [path moveToPoint:point1];
- [path addLineToPoint:point2];
- [path addLineToPoint:point3];
-
- self.animLayer.path = path.CGPath;
- }
- #pragma mark - animation delegate
- - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
-
- WeakSelf(weakSelf);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- if (weakSelf.finish) weakSelf.finish(flag);
- [weakSelf removeFromSuperview];
- });
- }
- #pragma mark - property
- - (CAShapeLayer *)animLayer{
- if (_animLayer == nil) {
- _animLayer = [[CAShapeLayer alloc]init];
- _animLayer.strokeColor = [UIColorFromRGB(0x00c8a9) CGColor];
- _animLayer.fillColor = [UIColor clearColor].CGColor;
- _animLayer.lineWidth = 2.5f;
- _animLayer.anchorPoint = CGPointMake(0.5, 0.5);
- _animLayer.backgroundColor = [UIColor whiteColor].CGColor;
- }
- return _animLayer;
- }
- - (UILabel *)titleLabel{
- if (_titleLabel == nil) {
- _titleLabel = [[UILabel alloc]init];
- _titleLabel.text = @"支付成功";
- _titleLabel.textColor = UIColorFromRGB(0x333333);
- _titleLabel.font = [UIFont systemFontOfSize:15];
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _titleLabel;
- }
- @end
|