显示脉冲效果的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. 电信固定ip宽带80与8080端口踩坑

    本文只是作为记录,避免后面遇到此类问题耗费时间. 实际情况:公司有个固定电信宽带是固定IP的,想把固定IP映射到测试环境ip,实现可以公网通过固定ip访问,内网通过局域网ip访问. 测试环境服务是占用 ...

  2. PTA (Advanced Level) 1024 Palindromic Number

    Palindromic Number A number that will be the same when it is written forwards or backwards is known ...

  3. Oracle相关

    where 条件中使用=进行限制时,可以返回一个记录集,即可以返回多个记录集

  4. 淺談 Entity 的概念

    延續上一篇文章<Drupal Commerce 概念架構>,本來打算要繼續講 Commerce 與 Views 整合的主題.不過由於這個主題牽涉到 Views 中的 Relationshi ...

  5. NSDictionary 和NSArray 排序(sort)

    排序: NSMutableDictionary *dic=[[NSMutableDictionary alloc]init]; [dic setValue:@"第3个" forKe ...

  6. mysql 修改初始化密码【转】

    转:http://www.jb51.net/article/39454.htm 方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password fo ...

  7. 《码出高效 Java开发手册》第四章 走进JVM(未整理)

    码云地址: https://gitee.com/forxiaoming/JavaBaseCode/tree/master/EasyCoding

  8. 郭霖 - MVVM开源项目学习

    https://blog.csdn.net/guolin_blog/article/details/87900605 https://medium.com/androiddevelopers/view ...

  9. jquery 对象的 height、innerHeight、outerHeight 的区别以及DOM 元素的 clientHeight、offsetHeight、scrollHeight、offsetTop、scrollTop

    前言:jquery 对象的 height.innerHeight.outerHeight,还有 DOM 元素的 clientHeight.offsetHeight.scrollHeight.offse ...

  10. Oracle用户权限及死锁

    Oracle用户权限表 oracle数据库中涉及到用户权限的三个表,dba_users,all_users,user_users有什么区别 dba_开头的是查全库所有的,all_开头的是查当前用户可以 ...