博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
显示脉冲效果的PulsingView
阅读量:7069 次
发布时间:2019-06-28

本文共 3806 字,大约阅读时间需要 12 分钟。

显示脉冲效果的PulsingView

效果如下:

源码:

PulsingView.h 与 PulsingView.m

////  PulsingView.h//  PulsingView////  Created by YouXianMing on 14/10/29.//  Copyright (c) 2014年 YouXianMing. All rights reserved.//#import 
@interface PulsingView : UIView/** * startScale与endScale需要设置值 */@property (nonatomic, assign) CGFloat startScale;@property (nonatomic, assign) CGFloat endScale;/** * 动画时间 */@property (nonatomic, assign) NSTimeInterval duration;/** * 最高程度的alpha */@property (nonatomic, assign) CGFloat maxAlpha;/** * 用来做动画的view */@property (nonatomic, strong) UIView *inputView;/** * 做动画 */- (void)startAnimation;@end
////  PulsingView.m//  PulsingView////  Created by YouXianMing on 14/10/29.//  Copyright (c) 2014年 YouXianMing. All rights reserved.//#import "PulsingView.h"@interface PulsingView ()@end@implementation PulsingView- (void)startAnimation {    CGFloat tmpStartScale = (_startScale < 0 ? 0.5 : _startScale);    CGFloat tmpEndScale   = (_endScale < 0 ? 2 : _endScale);        _inputView.transform  = CGAffineTransformMake(tmpStartScale, 0, 0, tmpStartScale, 0, 0);    _inputView.alpha      = ((_maxAlpha <= 0 || _maxAlpha > 1) ? 1: _maxAlpha);        [UIView animateWithDuration:(_duration <= 0 ? 1.f : _duration)                          delay:0.f options:UIViewAnimationOptionCurveEaseOut animations:^{                              _inputView.transform = CGAffineTransformMake(tmpEndScale, 0, 0, tmpEndScale, 0, 0);                              _inputView.alpha     = 0.f;                          } completion:nil];}@synthesize inputView = _inputView;- (void)setInputView:(UIView *)inputView {    _inputView       = inputView;    inputView.frame  = inputView.bounds; // 重设inputView的frame值    self.bounds      = inputView.bounds; // 重设view的bounds        // 先删除掉所有的子view    [[self subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {        UIView *tmp = (UIView *)obj;        [tmp removeFromSuperview];    }];        [self addSubview:inputView];}- (UIView *)inputView {    return _inputView;}@end

使用:

////  ViewController.m//  PulsingView////  Created by YouXianMing on 14/10/29.//  Copyright (c) 2014年 YouXianMing. All rights reserved.//#import "ViewController.h"#import "PulsingView.h"#import "YXGCD.h"@interface ViewController ()@property (nonatomic, strong) NSTimer     *timer;@property (nonatomic, strong) PulsingView *pulsingView;@property (nonatomic, strong) UIView      *circleView;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // 设置背景    self.view.backgroundColor      = [UIColor blackColor];     // 用来显示的view    _circleView                    = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];    _circleView.backgroundColor    = [self randomColor];    _circleView.layer.cornerRadius = 50.f;        // 脉冲view    _pulsingView            = [PulsingView new];    _pulsingView.inputView  = _circleView;    _pulsingView.startScale = 0.1f;    _pulsingView.duration   = 1.f;    _pulsingView.center     = self.view.center;    [self.view addSubview:_pulsingView];        // 定时器    _timer = [NSTimer scheduledTimerWithTimeInterval:1.2f                                              target:self                                            selector:@selector(animationTimerEvent)                                            userInfo:nil                                             repeats:YES];}- (void)animationTimerEvent {    _circleView.backgroundColor = [self randomColor];    _pulsingView.endScale       = arc4random()%200/100.f + 1.f;    [_pulsingView startAnimation];}- (UIColor *)randomColor {    return [UIColor colorWithRed:arc4random()%255/255.f                           green:arc4random()%255/255.f                            blue:arc4random()%255/255.f                           alpha:1.f];}@end

类的详细细节:

 

转载地址:http://jgqll.baihongyu.com/

你可能感兴趣的文章
(转)ubuntu简单命令
查看>>
转载:查看linux重启时间方法
查看>>
Eclipse快捷键 10个最有用的快捷键(快捷键都是可以自己定义的,以满足自己的使用习惯)...
查看>>
SQL事务日志备份时的问题
查看>>
HDU-1081-To The Max
查看>>
【海洋女神原创】How to: Installshield做安装包时如何添加文件
查看>>
会话标识未更新
查看>>
XCode使用技巧
查看>>
剑指offer数组2
查看>>
python基础之生成器迭代器
查看>>
python系统编程(二)
查看>>
洛谷P2894 [USACO08FEB]酒店Hotel
查看>>
bzoj千题计划159:bzoj2055: 80人环游世界(有源汇上下界可行最小费用流)
查看>>
pyhton3解决"tuple parameter unpacking is not supported"问题
查看>>
安装vmware vCenter Appliance
查看>>
PHP函数
查看>>
ORACLE 更新关联多张表
查看>>
弹性盒子布局
查看>>
SQL中的case when then else end用法
查看>>
【字王的野望】
查看>>