锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

OC 实现扫雷达扫描动画

时间:2023-02-12 11:30:00 控制电缆kyv绝缘电阻500mbfk系列通用继电器

先上效果如下:忽略CSDN动画显示效果严重下降,导致下面动画不流畅。

上代码:

typedef NS_ENUM(NSInteger,UISpinnerAnimationViewAnimation) {     UISpinnerAnimationViewAnimationSpinner,//拖尾绕圈     UISpinnerAnimationViewAnimationRador,  //雷达 };  @interface UISpinnerAnimationView : UIView  ///画笔厚度默认为6 @property (nonatomic,assign) CGFloat lineWidth; ///画笔轮廓颜色 @property (nonatomic,strong) UIColor *strokeColor; //填充颜色,如果使用雷达效果配置填充颜色 @property (nonatomic,strong) UIColor *fillColor;  /* An object providing the contents of the layer, typically a CGImageRef  * or an IOSurfaceRef, but may be something else. (For example, NSImage  * objects are supported on Mac OS X 10.6 and later.) Default value is nil.  * Animatable. */ @property (nonatomic,strong) UIImage *contentImage;  ///动画完成时间 @property (nonatomic,assign) CGFloat aniDuration;  @property (nonatomic,assign) UISpinnerAnimationViewAnimation animationType;  - (void)startAnimation; - (void)stopAnimation; @end

实现逻辑:

 typedef void (^UIProgressHUDViewCompleteBlock)(void); typedef UIView *(^UIProgressHUDInterfaceViewBlock)(void);  @implementation UISpinnerAnimationView  - (instancetype)initWithFrame:(CGRect)frame {     if ([super initWithFrame:frame])     {         self.lineWidth = 6;         self.strokeColor = [UIColor colorWithRed:2.0/255.0 green:134.0/255.0 blue:224.0/255.0 alpha:1];         self.animationType = UISpinnerAnimationViewAnimationSpinner;                  NSString *imageData = @"iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAQAAADTdEb AAAgRklEQVR42u2da5skx1GFM2dXMhd/hf/IL0OSEVhYMiBkrgbMHQwG2bqstbqaL8ADlqzVTifd09PbVdV5iThxIqp60c6zM9Pd1ZfpfOfEyZORNTn9R5r/y4PLoyP4l6y3IPevX8oBPwf3fWBdUnOQ08 GDzF6SA/QmIPwPILlDdno1iElB7CSGq1MAg0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XAG0pT+D9DyW48Ra0MyAAAAAElFTkSuQmCC";
        NSData *data = [[NSData alloc] initWithBase64EncodedString:imageData options:NSDataBase64DecodingIgnoreUnknownCharacters];
        UIImage *image = [UIImage imageWithData:data];
        
        self.contentImage = image;
        self.aniDuration = 1;
        
        [self.layer setMasksToBounds:YES];
        [self.layer setCornerRadius:frame.size.width / 2];
        [self.layer setBorderColor:[UIColor clearColor].CGColor];
    }
    return self;
}


- (void)startAnimation
{
    if (self.animationType == UISpinnerAnimationViewAnimationSpinner)
    {
        [self startSpinerAnimation];
    }
    else if (self.animationType == UISpinnerAnimationViewAnimationRador)
    {
        [self startRadorAnimation];
    }
}


- (void)startSpinerAnimation
{
    CGFloat lineWidth = self.lineWidth;
    CGPoint arcCenter = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);
    UIBezierPath *smoothedPath = [UIBezierPath bezierPath];
    [smoothedPath addArcWithCenter:arcCenter radius:self.frame.size.width / 2 startAngle:0 endAngle:2 * M_PI clockwise:YES];
    CAShapeLayer *layer = [CAShapeLayer layer];
    [layer setContentsScale:UIScreen.mainScreen.scale];
    [layer setFrame:CGRectMake(0, 0, arcCenter.x * 2, arcCenter.y * 2)];
    [layer setFillColor:UIColor.clearColor.CGColor];
    [layer setStrokeColor:self.strokeColor.CGColor];
    [layer setLineWidth:lineWidth];
    [layer setLineCap:kCALineCapRound];
    [layer setLineJoin:kCALineJoinBevel];
    [layer setPath:smoothedPath.CGPath];
    [layer setMask:[CALayer layer]];
    layer.mask.contents = (__bridge id _Nullable)(self.contentImage.CGImage);
    [layer.mask setFrame:self.bounds];
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.fromValue = [NSNumber numberWithFloat:0.0];
    animation.toValue = [NSNumber numberWithFloat:2 * M_PI];
    animation.duration = self.aniDuration;
    [animation setRemovedOnCompletion:NO];
    animation.repeatCount = HUGE_VALF;
    animation.autoreverses = NO;
    
    [layer addAnimation:animation forKey:@"rotate"];
    
    [self.layer addSublayer:layer];
}


- (void)startRadorAnimation
{
    CGFloat lineWidth = self.lineWidth;
    CGPoint arcCenter = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);
    UIBezierPath *smoothedPath = [UIBezierPath bezierPath];
    [smoothedPath addArcWithCenter:arcCenter radius:self.frame.size.width / 2 startAngle:0 endAngle:2 * M_PI clockwise:YES];
    CAShapeLayer *layer = [CAShapeLayer layer];
    [layer setContentsScale:UIScreen.mainScreen.scale];
    [layer setFrame:CGRectMake(0, 0, arcCenter.x * 2, arcCenter.y * 2)];
    [layer setFillColor:self.fillColor.CGColor];
    [layer setStrokeColor:self.strokeColor.CGColor];
    [layer setLineWidth:lineWidth];
    [layer setLineCap:kCALineCapRound];
    [layer setLineJoin:kCALineJoinBevel];
    [layer setPath:smoothedPath.CGPath];
    [layer setMask:[CALayer layer]];
    layer.mask.contents = (__bridge id _Nullable)(self.contentImage.CGImage);
    [layer.mask setFrame:self.bounds];
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.fromValue = [NSNumber numberWithFloat:0.0];
    animation.toValue = [NSNumber numberWithFloat:2 * M_PI];
    animation.duration = self.aniDuration;
    [animation setRemovedOnCompletion:NO];
    animation.repeatCount = HUGE_VALF;
    animation.autoreverses = NO;
    
    [layer addAnimation:animation forKey:@"rotate"];
    [self setBackgroundColor:self.fillColor];
    [self.layer addSublayer:layer];
}


- (void)stopAnimation
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [[self.layer sublayers] enumerateObjectsUsingBlock:^(__kindof CALayer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [obj removeAllAnimations];
        }];
    });
}

@end

使用方法:

CGFloat sz = MIN(self.view.bounds.size.width, self.view.bounds.size.height)/2;
    CGRect ft = CGRectMake((self.view.bounds.size.width-sz)/2, 120, sz, sz);
    UISpinnerAnimationView *c1View = [[UISpinnerAnimationView alloc] initWithFrame:ft];
    [c1View.layer setMasksToBounds:YES];
    [c1View.layer setCornerRadius:sz/2];
    [c1View setAnimationType:UISpinnerAnimationViewAnimationRador];
    [c1View setFillColor:[UIColor colorWithRed:2.0/255.0 green:134.0/255.0 blue:224.0/255.0 alpha:0.65]];
    [self.view addSubview:c1View];
    
    [c1View startAnimation];

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章