显示脉冲效果的PulsingView
显示脉冲效果的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的更多相关文章
- javascript超过容器后显示省略号效果(兼容一行或者多行)
javascript超过容器后显示省略号效果 在实际的项目中,由于文字内容的长度不确定性和页面布局的固定性,难免会出现文字内容超过div(或其他标签,下同)区域的情况,此时比较好的做法就是 ...
- js图片未加载完显示loading效果
<html> <title>js图片未加载完显示loading效果</title> <body> <style> img{float:lef ...
- UILabel混合显示动画效果
UILabel混合显示动画效果 效果 源码 https://github.com/YouXianMing/Animations // // MixedColorProgressViewControll ...
- JQuery鼠标移到小图显示大图效果的方法
JQuery鼠标移到小图显示大图效果的方法 本文实例讲述了JQuery鼠标移到小图显示大图效果的方法.分享给大家供大家参考.具体分析如下: 这里的显示大图功能类似上一篇<JQuery实现超链接鼠 ...
- anacoda的spyder在调用matplotlib的时候无法显示动画效果【学习笔记】
ipython console的默认设置将图像结果显示在终端,但是这样显示存在的问题是无法显示动画效果,因此需要将动画效果显示到单独的窗口,按照下面的截图即可显示. 方法一.按照如下截图显示设置,重启 ...
- 如何在Actionbarsherlock中一直显示overflow效果?
对Android开发一致性有一定考虑的程序员应当或多或少对Actionbarsherlock这个库有一定的了解.Actionbarsherlock的产生是因为Android在3.0(API 11)之后 ...
- [Unity3D]Unity3D游戏开发之在3D场景中选择物体并显示轮廓效果
大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei. 在<仙剑奇侠传>.<古剑奇谭>等游戏中,常常须要玩家在一个3D场景中 ...
- js鼠标滑动图片显示隐藏效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Android 类似未读短信图标显示数字效果的分析
之前一直以为是应用本身在对图标进行修改,看了源码之后发现其实主要的工作并不是应用自己完成的,主要的工作在是launcher里面完成的. 关于系统里面类似未读短信的具体处理流程如下, 原理 一个应用要实 ...
随机推荐
- android学习-Toast的延迟时间
一般显示Toast都是一条语句够了 Toast.makeText(Context context, CharSequence text, int duration) Context是要显示Toast的 ...
- struct in_addr 结构体
struct in_addr 结构体: struct in_addr { in_addr_t s_addr; }; 表示一个32位的IPv4地址. in_addr_t一般为32位的unsigned i ...
- 转载《浅析MVC框架中View层的优雅设计及实例》
在基于B/S的应用程序开发中,从基本的技术分工上来说就是两大块,一是软件显示界面,另一个是程序逻辑.在N年前的脚本语言时代,无论是asp.php还是jsp,我们基本是都是把这两者柔和在一起的.尽管我们 ...
- mvc中seeeion和cook的用法
public ActionResult A() { Session["test"]="123"; return View(); } public ...
- 结束回调事件(开头必须cp开头,JSProperties传参)
<dx:ASPxComboBox ID="comBrand" CssClass="case" ClientInstanceName="comBr ...
- java反射实现接口重试
工具类: import java.lang.reflect.Method; public class RetryUtil { private static ThreadLocal<Integer ...
- [日常] PHP设置 include_path 配置选项
动态设置php.ini中的include_path 配置选项: 两种方式set_include_path($new_include_path)ini_set('include_path',$new_i ...
- Java多线程学习之synchronized总结
0.概述 synchronized是Java提供的内置的锁机制,来实现代对码块的同步访问,称为内置锁(Intrinsic Lock) .内置锁包括两部分:一个是作为锁的对象的引用,另一个是由这个锁保护 ...
- 浅谈白鹭Egret
浅谈白鹭Egret 最近在做一个移动项目,技术选型的时候接触到了白鹭,简单了解了之后觉得挺合适的,最终就选择了这个引擎. 为什么会选择白鹭引擎呢? 我看上他主要有一下几点: 1 ...
- Python标准模块--concurrent.futures 进程池线程池终极用法
concurrent.futures 这个模块是异步调用的机制concurrent.futures 提交任务都是用submitfor + submit 多个任务的提交shutdown 是等效于Pool ...