显示脉冲效果的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里面完成的. 关于系统里面类似未读短信的具体处理流程如下, 原理 一个应用要实 ...
随机推荐
- xgboost使用
xgboost的实现方式为多颗CART树,其实xgboost就是类似于随机森林,但是与随机森林不同,他不是多个子树决策的结果,CART树最后会算出一个得分,是一个值,最后算出分类的时候,是多个值结合在 ...
- Linux C 遍历指定目录
#include<stdio.h> //标准输入输出 #include<unistd.h> //各种系统调用 #include<dirent.h> //与目录有关的 ...
- AI小白快上车!这是发往高薪职位的车!
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯云AI中心发表于云+社区专栏 AI到底有多火?看看下面这组数据: 腾讯研究院<2017全球人工智能人才白皮书>报告中提 ...
- SC Create 创建一个Windows系统服务 转
转自:http://www.360doc.com/content/13/0428/09/7555793_281451268.shtml sc create Serv-U binpath= &q ...
- CUBA 使用 Spring 查询接口
原文链接:https://www.cuba-platform.com/blog/spring-query-interfaces-in-cuba 翻译:CUBA China CUBA-Platform ...
- Css3盒子尺寸
box-sizing属性 用来改变盒模式中的宽度和高度默认的计算方式. box-sizing: 1.content-box(默认值): 宽度和高度只包含内容区域 2.border-box: 宽度和高度 ...
- 修改MVC视图默认搜索规则(IViewEngine)
前几天我自己在写一个系统,写到后台管理系统的时候,我突然有个想法就是:想在区域视图下新建文件,单独处理后台一些业务:Area/AdminManager/View/Content/Index.cshtm ...
- 【拓扑 && 模板】Kosaraju算法
#include<bits/stdc++.h> using namespace std; ; vector <int> g1[maxn],g2[maxn]; stack < ...
- SSM配置JDBC错误: cquisition Attempt Failed!!!
异常: 警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@20ffa401 -- Acquisition Attempt Fa ...
- Java Tools &Tools APIs
java 启动Java应用程序 javac Java编译器javac读取用Java编写的源文件,并将它们编译为字节码类文件. 用法: javac <options> <source ...