显示脉冲效果的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. 值得收藏的TCP套接口编程文章

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由jackieluo发表于云+社区专栏 TCP客户端-服务器典型事件 下图是TCP客户端与服务器之间交互的一系列典型事件时间表: 首先启 ...

  2. PL/SOL csv格式导出查询结果时出现某些列的数据被四舍五入了的解决办法

    昨天用pl/sql从oracle数据库捞取数据时,发现导出的csv格式中某些列的数据被进行了四舍五入处理了,当然这些列都是纯数字的,百思不得其解,后来上网才,才得知了原因. 这并不是导出的CSV文件数 ...

  3. Node.js之Express二

    好久没写了,今天看博客,觉得有必要把node.js继续写完,善始善终.原本想着把小崔课堂继续讲下去,由于其他原因也就此耽搁下来,看看以后还有没有机会吧.废话不扯,123开始. 一.Exoress之Re ...

  4. IOS开发常见第三方总结

    链接](https://github.com/languages​​/Objective-C/most_watched) * [three20](https://github.com/facebook ...

  5. C#比较两个字符串的相似度【转】

    原文地址:http://www.2cto.com/kf/201202/121170.html 我们在做数据系统的时候,经常会用到模糊搜索,但是,数据库提供的模糊搜索并不具备按照相关度进行排序的功能. ...

  6. Django(四):model

    一.创建model django.db.models是django自带的创建数据库的ORM. 在models.py中以继承models.Model创建表后,需要在setttngs中确保添加了当前应用, ...

  7. 整理 node-sass 安装失败的原因及解决办法

    npm install 时偶尔遇到报错:没有安装python或node-sass 安装失败的问题,百度之后发现是被墙了,但根据百度的方法换了淘宝镜像和用了vpn都安装失败,最后发现原来是因为没有卸载之 ...

  8. 神奇的Flex 布局

    layout是css中的一个重点.传统的页面布局是盒子模型,依赖 display属性 ,position属性 , float属性.它对于那些特殊布局非常不方便,而且定位用多了会出现挺多的bug. 所以 ...

  9. DOM增删操作(select动态增加和删除以及清空)

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  10. javaSE——简单的文件浏览器

    import java.io.File; public class Demo02 { public static void main(String[]args){ File file = new Fi ...