山寨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在这里分享给大家 这些插件对设计者和开发者都有很大的帮助,希望大家能够喜欢:) 现 今互联网市场上提 ...
随机推荐
- tensorflow summary
定义summary writer = tf.summary.FileWriter(logdir=self.han_config.log_path, graph=session.graph) 1.sca ...
- 生成类似于MongoDB产生的ObjectId
package com.jt.boot.utils; import com.google.common.base.Objects; import java.net.NetworkInterface; ...
- EF Core 实现多租户
目录 SAAS 和多租户 多租户数据隔离方案 使用 EF Core 简单实现多租户 单数据库实现 多数据库实现 源代码 参考 SAAS 和多租户 SaaS(软件及服务)区别于其他应用程序的主要特征就是 ...
- HAProxy Installation and Configuration on CentOS 6.4 to Mitigate The Effects of Abusive Clients--转
ref:http://thoughts.z-dev.org/2013/05/07/haproxy-installation-and-configuration-on-centos-6-4-to-mit ...
- Unity主线程和子线程跳转调用(2)
在上一篇介绍了多线程和Unity交互方式,但是由于我的项目是一个unity编辑器插件项目,很显然上一篇的代码需要加以修改,在编辑器下实现Loom. 1,Editor下的没有Update这个生命周期函数 ...
- 通过set赋值,与select赋值的区别
---通过set赋值,与select赋值的区别.declare @a int--set @a=(select count(*) from TblStudent)select @a=count(*) f ...
- AVFoundation-视频录制以及拍照
一般如果UI和UE在设计时只要求功能,对相机界面没什么要求的话,个人觉得调用系统相机(UIImagePickerController)就可以满足我们的需求比如照相或者录制视频,但是考虑界面美观性,有时 ...
- [C#]简单离线注册码生成与验证
本文使用RSA非对称加密和Base64简单地实现离线注册码的生成与验证功能. 主要思路就是提供者持有密钥,通过RSA加密客户机标识或时间标识,再通过Base64加密成不太难看的注册码,然后分发给客户机 ...
- java 二分法
源码 public class Dichotomy { public static void main(String[] args){ int[] array = new int[12]; for(i ...
- django(五):cookie和session
一.Cookie 1.cookie机制 会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确 ...