山寨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在这里分享给大家 这些插件对设计者和开发者都有很大的帮助,希望大家能够喜欢:) 现 今互联网市场上提 ...
随机推荐
- java 实现 HTTP请求(GET、POST)的方法
使用Java进行服务调用时,避免不了要使用模拟HTTP请求来实现模拟,我在开发过程中恰巧遇到了这类的业务需求,所以就对这类的方法进行了一次总结,原理层次的东西暂时不考虑,毕竟HTTP的底层实现啥的,东 ...
- H5开发过程中修复的bug记录
从2016年8月1日开始真正意义上的修复bug,也是自己开发之路的开端,希望在这里记录自己修bug过程中遇到的问题及解决方法,待能够自己开发需求的时候,计划记录开发新需求过程中遇到的问题,并且记录自己 ...
- [PY3]——发送邮件
一些概念 MUA:Mail User Agent——邮件用户代理,例如OutLook.Foxmail MTA:Mail Transfer Agent——邮件传输代理,例如163.com.sina.co ...
- C#语法之Linq查询基础一
Linq做.Net开发的应该都用过,有些地方很复杂的逻辑用Linq很方便的解决.对于Linq to object.Linq to xml.Linq to sql.Linq to Entity(EF)都 ...
- datalist控件及list属性
html5新增了一个datalist元素,可以实现数据列表的下拉效果,气外观类似autocomplete,用户可从列表中选择,也可自行输入,而list用户指定输入框绑定哪一个datalist元素,其值 ...
- FileStream文件的使用
// FileStream//(操作字节的)水一勺一勺的 可以操作任意格式的文件 //File一下子就读出来 //读取文本文件 // FileMode.OpenOrCreate你针 ...
- SpingMVC_注解式开发_接收请求参数
一.逐个接收 import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotat ...
- K:图的存储结构
常用的图的存储结构主要有两种,一种是采用数组链表(邻接表)的方式,一种是采用邻接矩阵的方式.当然,图也可以采用十字链表或者边集数组的方式来进行表示,但由于不常用,为此,本博文不对其进行介绍. 邻接 ...
- 去除底部“自豪地采用 WordPress”版权信息----最后附最新版的删除方法!!
footer.php get_template_part( 'template-parts/footer/site', 'info' );
- Implementation:Dijkstra
#include <iostream> #include <cstdlib> #include <utility> #include <queue> u ...