山寨Facebook的Shimmer效果
山寨Facebook的Shimmer效果

说明
主要是用到了CAGradientLayer的特性来实现特效效果,因为时间有限,并没有进行封装,待后续改进.
效果

源码(源码没有进行封装,细节都没有处理,望见谅)
//
// FadeString.h
// FadeWords
//
// Created by YouXianMing on 15/5/7.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface FadeString : UIView /**
* 输入文本
*/
@property (nonatomic, strong) NSString *text; /**
* 向右渐变消失
*/
- (void)fadeRight; @end
//
// FadeString.m
// FadeWords
//
// Created by YouXianMing on 15/5/7.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "FadeString.h" @interface FadeString () @property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UILabel *backLabel;
@property (nonatomic, strong) UIView *mask; // 作为遮罩的mask @end @implementation FadeString - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) { // 创建出label
[self createLabel:self.bounds]; // 创建出mask
[self createMask:self.bounds]; }
return self;
} - (void)createLabel:(CGRect)frame {
self.label = [[UILabel alloc] initWithFrame:frame];
self.label.font = [UIFont fontWithName:@"AvenirNext-ULtraLight" size:.f];
self.label.textAlignment = NSTextAlignmentCenter;
self.label.textColor = [[UIColor cyanColor] colorWithAlphaComponent:0.5f]; [self addSubview:self.label];
} - (void)createMask:(CGRect)frame { // 创建出渐变的layer
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = frame;
gradientLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor,
(__bridge id)[UIColor blackColor].CGColor,
(__bridge id)[UIColor blackColor].CGColor,
(__bridge id)[UIColor clearColor].CGColor];
gradientLayer.locations = @[@(0.01), @(0.2), @(0.4), @(0.59)];
gradientLayer.startPoint = CGPointMake(, );
gradientLayer.endPoint = CGPointMake(, ); // 创建并接管mask
self.mask = [[UIView alloc] initWithFrame:frame]; // mask获取渐变layer
[self.mask.layer addSublayer:gradientLayer]; CGRect newFrame = self.mask.frame;
newFrame.origin.x -= ;
self.mask.frame = newFrame; self.maskView = self.mask;
} - (void)fadeRight { [UIView animateWithDuration:.f animations:^{
CGRect frame = self.mask.frame;
frame.origin.x += (frame.size.width + ); self.mask.frame = frame;
}]; } /**
* 重写setter,getter方法
*/
@synthesize text = _text;
- (void)setText:(NSString *)text {
_text = text;
self.label.text = text;
}
- (NSString *)text {
return _text;
} @end
//
// ViewController.m
// FadeWords
//
// Created by YouXianMing on 15/5/7.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "ViewController.h"
#import "FadeString.h" @interface ViewController () @property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) FadeString *fadeString; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.view.backgroundColor = [UIColor blackColor]; self.label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
self.label.font = [UIFont fontWithName:@"AvenirNext-ULtraLight" size:.f];
self.label.center = self.view.center;
self.label.textAlignment = NSTextAlignmentCenter;
self.label.textColor = [UIColor grayColor];
self.label.text = @"YouXianMing";
[self.view addSubview:self.label]; // 创建FadeString
self.fadeString = [[FadeString alloc] initWithFrame:CGRectMake(, , , )];
self.fadeString.text = @"YouXianMing";
self.fadeString.center = self.view.center;
[self.view addSubview:self.fadeString]; [self performSelector:@selector(run)
withObject:nil
afterDelay:.f];
} - (void)run {
// 执行动画效果
[self.fadeString fadeRight];
} @end
关键的设置

山寨Facebook的Shimmer效果的更多相关文章
- Facebook 开源微光效果 Shimmer
我的引言 晚上好,我是吴小龙同学,我的公众号「一分钟 GitHub」会推荐 GitHub 上好玩的项目,挖掘开源的价值,欢迎关注我. 今天要推荐的是 Facebook 开源的闪光效果:Shimmer, ...
- <转>如何在iOS 7中设置barTintColor实现类似网易和 Facebook 的 navigationBar 效果
转自:i‘m Allen的博客 先给代码:https://github.com/allenhsu/CRNavigationController 1. 问题的表现 相信很多人在 iOS 7 的适配过程中 ...
- Asp.net+jquery+ajaxpro异步仿Facebook纵向时间轴效果
Asp.net+jquery+ajaxpro异步仿Facebook纵向时间轴效果 在一个项目中,用到了时间轴展示产品的开发进度,为了更好用户体验,想到了Facebook的timeline效果, 搜了一 ...
- FaceBook微光闪烁---第三方开源--shimmer-android
Android上的微光闪烁shimmer效果,实现的手段不少,其中比较好的是facebook做的开源库:shimmer-android,其在github上的项目主页是:https://github.c ...
- iOS歌词逐渐变色动画
实现歌词逐渐变色的动画,像卡拉OK一样可以根据时间进度来染色.效果如图: 因项目需求要实现一个类似歌词逐渐变色的效果,自己想来想去想不出来实现方案,还是得求助万能的google, 最终是找到了这篇 ...
- github优秀开源项目大全-iOS
github优秀开源项目大全-iOS APR 25TH, 2014 前言 本文旨在搜集github上优秀的开源项目 本文搜集的项目都是用于iOS开发 本文会持续更新… 完整客户端 ioctocat g ...
- IOS-github优秀开源项目大全
github优秀开源项目大全-iOS 前言 本文旨在搜集github上优秀的开源项目 本文搜集的项目都是用于iOS开发 本文会持续更新… 完整客户端 ioctocat github的iOS客户端,目前 ...
- 用jQuery Mobile做HTML5移动应用的三个优缺点
JQuery Mobile 和 HTML5 的 3个优点 1. 上手迅速并支持快速迭代:在一个星期多一点的时间里,通过阅读JQuery Mobile文档以及O’Reilly出版的JQuery Mobi ...
- 2014优秀的好用的20款免费jQuery插件推荐
2013 年最好的 20 款免费 jQuery 插件,世界买家网 www.buyerinfo.biz在这里分享给大家 这些插件对设计者和开发者都有很大的帮助,希望大家能够喜欢:) 现 今互联网市场上提 ...
随机推荐
- YAOLEI
http://www.cnblogs.com/skyblue/p/3356933.html
- 用java实现编译器-算术表达式及其语法解析器的实现
大家在参考本节时,请先阅读以下博文,进行预热: http://blog.csdn.net/tyler_download/article/details/50708807 本节代码下载地址: http: ...
- after_create and after_commit
A relational database, like mysql, provides transactions to wrap several operations in one unit, mak ...
- sql中替换换行符和空格的示例
select DiscussID,L.Name as LocationName , C.Name as ClientName, REPLACE(BrandName,' ','') BrandName ...
- cmd下命令提示符下杀进程主要有三种方法
https://blog.csdn.net/sunboy2718/article/details/30056787 1.用taskkill命令 1.taskkill /im 进程名称 示例:用task ...
- Java常见对象之String
String类的概述 String 类代表字符串.Java 程序中的所有字符串字面值(如 "abc" )都作为此类的实例实现.字符串是常量,一旦被赋值,就不能被改变. String ...
- [javaSE] 网络编程(UDP通信)
UDP发送端 获取DatagramSocket对象,new出来 获取DatagramPacket对象,new出来,构造参数:byte[]数组,int长度,InetAddress对象,int端口 调用D ...
- git 查看暂存区
一.简介 git ls-files 命令是用来查看暂存区中文件信息 二.常用参数 参数说明(括号里是简写) --cached(-c)显示暂存区中的文件,git ls-files命令默认的参数 --de ...
- ASP.NET MVC传递Model到视图的多种方式总结(一)__通用方式的使用
有多种方式可以将数据传递到视图,如下所示: ViewData ViewBag PartialView TempData ViewModel Tuple 场景: 在视图页面,下拉框选择课程触发事件,分别 ...
- WPF流程图制作系列相关基础一
WPF流程图制作相关基础一 需求是要通过wpf开发流程图,这个流程图是用户自行拖动配置. 使用过流程图的话,应该大体能想象出流程图拖动配置的样子.这里主要会涉及到的技术知识点就是 wpf拖动相 ...