显示脉冲效果的PulsingView

效果如下:

源码:

PulsingView.h 与 PulsingView.m

//
// PulsingView.h
// PulsingView
//
// Created by YouXianMing on 14/10/29.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @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.5 : _startScale);
CGFloat tmpEndScale = (_endScale < ? : _endScale); _inputView.transform = CGAffineTransformMake(tmpStartScale, , , tmpStartScale, , );
_inputView.alpha = ((_maxAlpha <= || _maxAlpha > ) ? : _maxAlpha); [UIView animateWithDuration:(_duration <= ? .f : _duration)
delay:.f options:UIViewAnimationOptionCurveEaseOut animations:^{
_inputView.transform = CGAffineTransformMake(tmpEndScale, , , tmpEndScale, , );
_inputView.alpha = .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(, , , )];
_circleView.backgroundColor = [self randomColor];
_circleView.layer.cornerRadius = .f; // 脉冲view
_pulsingView = [PulsingView new];
_pulsingView.inputView = _circleView;
_pulsingView.startScale = 0.1f;
_pulsingView.duration = .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()%/.f + .f;
[_pulsingView startAnimation];
} - (UIColor *)randomColor {
return [UIColor colorWithRed:arc4random()%/.f
green:arc4random()%/.f
blue:arc4random()%/.f
alpha:.f];
} @end

类的详细细节:

显示脉冲效果的PulsingView的更多相关文章

  1. javascript超过容器后显示省略号效果(兼容一行或者多行)

    javascript超过容器后显示省略号效果       在实际的项目中,由于文字内容的长度不确定性和页面布局的固定性,难免会出现文字内容超过div(或其他标签,下同)区域的情况,此时比较好的做法就是 ...

  2. js图片未加载完显示loading效果

    <html> <title>js图片未加载完显示loading效果</title> <body> <style> img{float:lef ...

  3. UILabel混合显示动画效果

    UILabel混合显示动画效果 效果 源码 https://github.com/YouXianMing/Animations // // MixedColorProgressViewControll ...

  4. JQuery鼠标移到小图显示大图效果的方法

    JQuery鼠标移到小图显示大图效果的方法 本文实例讲述了JQuery鼠标移到小图显示大图效果的方法.分享给大家供大家参考.具体分析如下: 这里的显示大图功能类似上一篇<JQuery实现超链接鼠 ...

  5. anacoda的spyder在调用matplotlib的时候无法显示动画效果【学习笔记】

    ipython console的默认设置将图像结果显示在终端,但是这样显示存在的问题是无法显示动画效果,因此需要将动画效果显示到单独的窗口,按照下面的截图即可显示. 方法一.按照如下截图显示设置,重启 ...

  6. 如何在Actionbarsherlock中一直显示overflow效果?

    对Android开发一致性有一定考虑的程序员应当或多或少对Actionbarsherlock这个库有一定的了解.Actionbarsherlock的产生是因为Android在3.0(API 11)之后 ...

  7. [Unity3D]Unity3D游戏开发之在3D场景中选择物体并显示轮廓效果

    大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei. 在<仙剑奇侠传>.<古剑奇谭>等游戏中,常常须要玩家在一个3D场景中 ...

  8. js鼠标滑动图片显示隐藏效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. Android 类似未读短信图标显示数字效果的分析

    之前一直以为是应用本身在对图标进行修改,看了源码之后发现其实主要的工作并不是应用自己完成的,主要的工作在是launcher里面完成的. 关于系统里面类似未读短信的具体处理流程如下, 原理 一个应用要实 ...

随机推荐

  1. IOS应用图标尺寸

    Table 41-1Size (in pixels) of custom icons and images Asset iPhone 6 Plus (@3x) iPhone 6 and iPhone ...

  2. MyEclipse中设置代码块快捷键

    如果想用快捷键生成一段自定义代码,可以通过下面方式设置: Java->Editor->Templates->New 如果要设置或者更改某个快捷键,如要设置保存全部文档的快捷键(系统默 ...

  3. 啰哩吧嗦式讲解在windows 家庭版安装docker

    1.docker是什么,为什么要使用docker Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中, 然后发布到任何流行的 Linux 机器上,也可以实 ...

  4. 招新系统(jsp+servlet,实现简略前端网页注册登录+后台增删改查,分学生和管理员,Java语言,mysql数据库连接,tomcat服务器)

    生活不只是眼前的苟且,还有诗和远方. 架构说明: 要求是采用MVC模式,所以分了下面的几个包,但是由于是第一次写,可能分的也不是很清楚: 这个是后台部分的架构: 这个是前端的的展示: (那个StuLo ...

  5. 鼓捣phantomjs,做ajax网站的信息采集

    版权所有:http://www.cnblogs.com/zeusro/ 引用不给稿费的,切你jj 准备工作: 1phantomjs的安装 2 phantomjs环境变量的配置 需求: 采集手机淘宝某店 ...

  6. 资源在Windows编程中的应用

    学习目的 掌握菜单和对话框资源的创建和使用. 编写程序: 设计一个窗口应用程序, 其中有一个VC菜单, 该菜单下有"显示", "隐藏", "退出&qu ...

  7. Java开发中常用的设计模式(三)---建造者模式

    一. 模式结构 建造者模式主要包含四个角色: Product:产品角色. Builder:抽象建造者.它声明为创建一个Product对象的各个部件指定的抽象接口. ConcreteBuilder:具体 ...

  8. 【学习笔记】--- 老男孩学Python,day7 python中is 和 == 的区别 encode decode

    is比较的是id(内存地址)是不是一样,==比较的是值是不是一样 Python中,万物皆对象!万物皆对象!万物皆对象!(很重要,重复3遍) 每个对象包含3个属性,id,type,value id就是对 ...

  9. Linux:网络工具 nc

    虽然叫nc不过用起来非常方便. 选项 - Use IPv4 only - Use IPv6 only -U, --unixsock Use Unix domain sockets only -C, - ...

  10. C#(简单递归)和实现IComparable接口

    递归: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...