倒计时特效的CountAnimationLabel
倒计时特效的CountAnimationLabel

效果:

源码:
CountAnimationLabel.h 与 CountAnimationLabel.m
//
// CountAnimationLabel.h
// YouXianClock
//
// Created by YouXianMing on 14-10-14.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface CountAnimationLabel : UIView @property (nonatomic, strong) NSString *text; // 文本的文字
@property (nonatomic, strong) UIFont *font; // 文本的字体 @property (nonatomic, assign) CGFloat startScale; // 最初处于alpha = 0状态时的scale值
@property (nonatomic, assign) CGFloat endScale; // 最后处于alpha = 0状态时的scale值 @property (nonatomic, strong) UIColor *backedLabelColor; // 不会消失的那个label的颜色 @property (nonatomic, assign) NSTimeInterval fadeInDuration; // 默认值为1s
@property (nonatomic, assign) NSTimeInterval fadeOutDuration; // 默认值为2s
@property (nonatomic, assign) NSTimeInterval showDuration; // 默认值为0.5s
@property (nonatomic, assign) BOOL removeOnComplete; // 动画结束后是否被移除掉 - (void)startAnimation; @end
//
// CountAnimationLabel.m
// YouXianClock
//
// Created by YouXianMing on 14-10-14.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "CountAnimationLabel.h" @interface CountAnimationLabel () @property (nonatomic, strong) UILabel *backedLabel; @end @implementation CountAnimationLabel - (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_backedLabel = [[UILabel alloc] initWithFrame:self.bounds]; // 初始时的alpha值为0
_backedLabel.alpha = ; // 文本居中
_backedLabel.textAlignment = NSTextAlignmentCenter; [self addSubview:_backedLabel];
}
return self;
} - (void)startAnimation
{
// 判断endScale的值
if (_endScale == ) {
_endScale = .f;
} // 开始第一次动画
[UIView animateWithDuration:(_fadeInDuration > ?_fadeInDuration : .f)
delay:
usingSpringWithDamping:
initialSpringVelocity:
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
// 恢复正常尺寸
_backedLabel.alpha = .f;
_backedLabel.transform = CGAffineTransformMake(, , , , , );
}
completion:^(BOOL finished) { // 开始第二次动画
[UIView animateWithDuration:(_fadeOutDuration > ? _fadeOutDuration : .f)
delay:(_showDuration > ? _showDuration : 0.5f)
usingSpringWithDamping:
initialSpringVelocity:
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
_backedLabel.alpha = .f;
_backedLabel.transform = CGAffineTransformMake(_endScale, , , _endScale, , );
}
completion:^(BOOL finished) {
if (_removeOnComplete == YES) {
[self removeFromSuperview];
}
}];
}];
} #pragma mark - 重写setter,getter方法
#pragma mark - 重写setter方法
@synthesize text = _text;
- (void)setText:(NSString *)text
{
_text = text;
_backedLabel.text = text;
}
- (NSString *)text
{
return _text;
} @synthesize startScale = _startScale;
- (void)setStartScale:(CGFloat)startScale
{
_startScale = startScale;
_backedLabel.transform = CGAffineTransformMake(startScale, , , startScale, , );
}
- (CGFloat)startScale
{
return _startScale;
} @synthesize font = _font;
- (void)setFont:(UIFont *)font
{
_font = font;
_backedLabel.font = font;
}
- (UIFont *)font
{
return _font;
} @synthesize backedLabelColor = _backedLabelColor;
- (void)setBackedLabelColor:(UIColor *)backedLabelColor
{
_backedLabelColor = backedLabelColor;
_backedLabel.textColor = backedLabelColor;
} @end
以下是使用详情:

倒计时特效的CountAnimationLabel的更多相关文章
- JS倒计时特效--JavaScript基础
1.倒计时特效HTML源码 <!DOCTYPE html><html lang="en"><head> <meta charset=&qu ...
- 基于jQuery个性圆圈倒计时特效
基于jQuery个性圆圈倒计时特效里面包含十几款不用效果的jQuery倒计时特效下载.效果图如下: 在线预览 源码下载 实现的代码. html代码: <section class=" ...
- jQuery实现的手机发送验证码倒计时效果代码分享
这是一款基于jquery实现的手机发送验证码倒计时效果代码,可实现实时显示秒数倒计时的功能,还可实现对手机号码格式验证的功能,是一款常用的网站注册发送手机验证码特效代码. 效果描述:注册一个网站,当需 ...
- 利用Javascript制作网页特效(时间特效)
在网页中经常可以看到各种各样的动态时间显示,在网页中合理地使用时间可以增加网页的时效感. 显示当前时间 getHours().getMinutes().getSeconds()分别获得当前小时数.当前 ...
- Matches正则使用提取内容
用VS新建WinForm程序,窗体上是三个文本框和一个按钮.可以自己构造正则表达式,自己修改匹配内容 正则表达是要提取的部分为hewenqitext 代码如下: using System; using ...
- javascript基础07
javascript基础07 1.节点 元素.childNodes : 属性 只读 属性 子节点列表集合 元素.childNodes 只包含子节点,不包含孙节点 DOM节点的类型有很多种,w3c标准有 ...
- javascript特效实现(4)——当前时间和倒计时效果
这个效果的实现关键是对Date对象和setTimeout的使用. 一共有三个例子,HTML结构如下,就不添加CSS样式了. <body> 当前时间:<p id="p1&qu ...
- 每天一个JS 小demo之商品下架特效制作,主要知识点:定时器,倒计时,抖动特效。PS:由于不方便上传文件夹,只能上传效果图,图片等素材需自寻哟。
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- jquery特效(8)—倒计时
最近公司在做一个答题的小游戏,每道题可以有20秒时间作答,超过时间就要给出相应的提醒,由于20秒时间太长,不适合做GIF动态图,下面来看一下我写的5秒倒计时的测试程序结果: 一.主体程序: <! ...
随机推荐
- 第1章—Spring之旅—Spring模块介绍
Spring模块介绍 Spring7大核心模块: 核心容器(Spring Core) 核心容器提供Spring框架的基本功能.Spring以bean的方式组织和管理Java应用中的各个组件及其关系.S ...
- windows7用WMware安装Linux虚拟机详细步骤
一.安装环境 windows7操作系统物理机VMware Workstation 软件(可以在网上下载)CentOS6.5镜像文件(其他版本都大同小异,这里以CentOS6.5为例)Cnetos6.5 ...
- javac的访问者模式
这一篇重点来总结下javac的访问者模式,其定义的访问者接口为JCTree.Visitor,具体如下: /** A generic visitor class for trees. */ public ...
- python-thread多线程
#!/usr/bin/python import threading,time def Music(): print "music is playing" time.sleep(3 ...
- android4.0 4.1 4.2 4.3 4.4新特性
http://blog.csdn.net/kaiyang45/article/details/7179349 4.0 http://digi.tech.qq.com/a/20120628/000827 ...
- <数据挖掘导论>读书笔记9聚类分析
1. 聚类分析仅根据在数据中发现的描述对象及其关系的信息,将数据对象分组. 其目标是组内的对象相互之间是相似的或者相关的,而不同组中的对象是不同的或者不相关的. 2.聚类分析的重要技术 K均值:K均值 ...
- webstorm中es6语法报错,.vue文件中es6语法报错
1.webstorm中es6语法报错,解决方法: 打开 Settings => Languages & Frameworks => Javascript把 Javascript L ...
- javascript图形动画设计--画简单正弦波
<!doctype html> <html> <head> <meta charset="utf-8"> <title ...
- 使用k8s创建容器一直处于ContainerCreating状态
容器报错信息为(两种): FailedSynError syncing pod, skipping: failed to {kubelet 127.0.0.1} Warning FailedSync ...
- FusionChart实现柱状图、饼状图的动态数据显示
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...