倒计时特效的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的更多相关文章

  1. JS倒计时特效--JavaScript基础

    1.倒计时特效HTML源码 <!DOCTYPE html><html lang="en"><head> <meta charset=&qu ...

  2. 基于jQuery个性圆圈倒计时特效

    基于jQuery个性圆圈倒计时特效里面包含十几款不用效果的jQuery倒计时特效下载.效果图如下: 在线预览   源码下载 实现的代码. html代码: <section class=" ...

  3. jQuery实现的手机发送验证码倒计时效果代码分享

    这是一款基于jquery实现的手机发送验证码倒计时效果代码,可实现实时显示秒数倒计时的功能,还可实现对手机号码格式验证的功能,是一款常用的网站注册发送手机验证码特效代码. 效果描述:注册一个网站,当需 ...

  4. 利用Javascript制作网页特效(时间特效)

    在网页中经常可以看到各种各样的动态时间显示,在网页中合理地使用时间可以增加网页的时效感. 显示当前时间 getHours().getMinutes().getSeconds()分别获得当前小时数.当前 ...

  5. Matches正则使用提取内容

    用VS新建WinForm程序,窗体上是三个文本框和一个按钮.可以自己构造正则表达式,自己修改匹配内容 正则表达是要提取的部分为hewenqitext 代码如下: using System; using ...

  6. javascript基础07

    javascript基础07 1.节点 元素.childNodes : 属性 只读 属性 子节点列表集合 元素.childNodes 只包含子节点,不包含孙节点 DOM节点的类型有很多种,w3c标准有 ...

  7. javascript特效实现(4)——当前时间和倒计时效果

    这个效果的实现关键是对Date对象和setTimeout的使用. 一共有三个例子,HTML结构如下,就不添加CSS样式了. <body> 当前时间:<p id="p1&qu ...

  8. 每天一个JS 小demo之商品下架特效制作,主要知识点:定时器,倒计时,抖动特效。PS:由于不方便上传文件夹,只能上传效果图,图片等素材需自寻哟。

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. jquery特效(8)—倒计时

    最近公司在做一个答题的小游戏,每道题可以有20秒时间作答,超过时间就要给出相应的提醒,由于20秒时间太长,不适合做GIF动态图,下面来看一下我写的5秒倒计时的测试程序结果: 一.主体程序: <! ...

随机推荐

  1. python-无名管道进程通信

    #!/usr/bin/python #coding=utf-8 import sys,os from time import sleep (r,w)=os.pipe() #创建无名管道,返回两个整数, ...

  2. nginx故障分析与记录

    本文是对于自己遇到nginx故障的一些记录.便于以后解决问题. 时间:2018_05_11 场景一:某天很多客户在群里反应说访问网站不了,报504错误. 环境:首先说明一点的就是公司网站是美国,日本等 ...

  3. WPF中C#代码触发鼠标点击事件

    1.如下代码; <Button x:Name="btnTest" Click="btnTest_Click"> <Button.Trigger ...

  4. Integer 与 int -- 自动装箱(autoboxing)与自动拆箱(unboxing)

    转载于 http://www.ticmy.com/?p=110 jdk1.5引入了自动装箱(autoboxing)与自动拆箱(unboxing),这方便了集合类以及一些方法的调用,同时也使初学者对其感 ...

  5. HDU 6187 Destroy Walls

    Destroy Walls Long times ago, there are beautiful historic walls in the city. These walls divide the ...

  6. 深入redis内部--字典实现

    redis的字典定义和实现在dict.h和dict.c文件中. 1.字典结构 typedef struct dict { dictType *type; //定义了字典需要的函数 void *priv ...

  7. 打乱数组——shuffle

    在学习vue移动端音乐项目时,看到一个打乱数组函数,感觉很有意思就记录一下(意外发现:slice是个有趣的知识点) 原理:遍历数组,(let i = 0; i < _arr.length; i+ ...

  8. i.mx6 Android5.1.1 初始化流程之init.rc解析(未完成)

    接上一篇:i.mx6 Android5.1.1 初始化流程之init进程 参考资料:http://blog.csdn.net/mr_raptor/article/category/799879 这个博 ...

  9. 【C#高级】泛型(一)

    泛型,.net 2.0之后出现,基本只要代码中出现 ‘<>’ 尖括号就可以确定是泛型. 在2.0之前大多是使用Object来代替,因为所有类都是Object的派生类,根据继承的原理Obje ...

  10. C++类数组的实现

    请看下面的代码: //xy_3_1 2013/10/26 #include<stdio.h> #include<iostream.h> #include<string.h ...