通过cagradientLayer类封装uiimageview动画色度差
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, EcolorDirectionType)
{
EcolorDirectionUp, //上
EcolorDirectionDown, //下
EcolorDirectionRight, //右
EcolorDirectionLeft, //左
};
@interface ColorImageView : UIImageView /**
* @brief 确定方向
*/
@property(nonatomic,assign) EcolorDirectionType direction; /**
* @brief 颜色
*/
@property(nonatomic,strong) UIColor *color; /**
* @brief 百分比
*/
@property(nonatomic,assign) CGFloat percent; @end
#import "ColorImageView.h"
@interface ColorImageView ()
{
CAGradientLayer *_gradientLayer;
}
@end
@implementation ColorImageView
@synthesize color = _color;
@synthesize percent = _percent;
@synthesize direction = _direction; - (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
_gradientLayer = [CAGradientLayer layer];
_gradientLayer.frame = self.bounds;
_gradientLayer.borderWidth = 1.0f;
_gradientLayer.colors = @[ (__bridge id)[UIColor clearColor].CGColor,
(__bridge id)[UIColor redColor].CGColor
];
_gradientLayer.locations = @[@(0.1),@()]; [self.layer addSublayer:_gradientLayer];
}
return self;
}
/**
* @brief 设置颜色
* @param color 重写setter方法
*/
- (void)setColor:(UIColor *)color
{
_color = color;
_gradientLayer.colors = @[ (__bridge id)[UIColor clearColor].CGColor,
(__bridge id)color.CGColor
];
}
- (UIColor *)color
{
return _color;
}
/**
* @brief 设置颜色分割点
* @param percent 重写setter方法
*/
- (void)setPercent:(CGFloat)percent
{
_percent = percent;
_gradientLayer.locations= @[@(percent),@()];
} -(CGFloat)percent
{
return _percent;
} /**
* @brief 设置颜色渐变方向
* @param direction 重写setter方法
*/
-(void)setDirection:(EcolorDirectionType)direction
{
_direction=direction;
switch (direction) {
case EcolorDirectionUp:
{
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, );
}
break;
case EcolorDirectionDown:
{
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, ); }
break;
case EcolorDirectionLeft:
{
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, ); }
break;
case EcolorDirectionRight:
{
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, );
}
break;
default:
{
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, );
}
break;
}
}
-(EcolorDirectionType)direction
{
return _direction;
}
@end
#import "ViewController.h"
#import "ColorImageView.h"
@interface ViewController ()
{ ColorImageView *_imvColor;
}
@end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad]; _imvColor=[[ColorImageView alloc]initWithFrame:CGRectMake(, , , )];
_imvColor.image = [UIImage imageNamed:@""];
_imvColor.center = self.view.center; [self.view addSubview:_imvColor];
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(event) userInfo:nil repeats:YES];
// [self performSelector:@selector(event) withObject:nil afterDelay:2.0f]; }
- (void)event
{
_imvColor.direction=EcolorDirectionUp;
_imvColor.color=[UIColor cyanColor];
_imvColor.percent=arc4random()%/.f;
}
@end
通过cagradientLayer类封装uiimageview动画色度差的更多相关文章
- iOS常用动画 类封装
//这是一个很好的动画封装类 很容易明白很详细 和大家分享 // CoreAnimationEffect.h // CoreAnimationEffect // // Created by Vince ...
- 原生Js封装的动画类
算法用的是Tween类,需要研究的参考这篇文章: http://www.cnblogs.com/cloudgamer/archive/2009/01/06/Tween.html 网页里常用的动画 放大 ...
- .Net Core ORM选择之路,哪个才适合你 通用查询类封装之Mongodb篇 Snowflake(雪花算法)的JavaScript实现 【开发记录】如何在B/S项目中使用中国天气的实时天气功能 【开发记录】微信小游戏开发入门——俄罗斯方块
.Net Core ORM选择之路,哪个才适合你 因为老板的一句话公司项目需要迁移到.Net Core ,但是以前同事用的ORM不支持.Net Core 开发过程也遇到了各种坑,插入条数多了也特别 ...
- salesforce 零基础学习(四十八)自定义列表分页之Pagination基类封装 ※※※
我们知道,salesforce中系统标准列表页面提供了相应的分页功能,如果要使用其分页功能,可以访问http://www.cnblogs.com/zero-zyq/p/5343287.html查看相关 ...
- 原生JS封装简单动画效果
原生JS封装简单动画效果 一致使用各种插件,有时候对原生JS陌生了起来,所以决定封装一个简单动画效果,熟悉JS原生代码 function animate(obj, target,num){ if(ob ...
- 在Android中动画移动一个View的位置,采用Scroller类实现Android动画之 View移动
在Android中动画移动一个View的位置,采用Scroller类实现 今天说最近自己遇到的一个问题,就是要用动画效果来移动一个VIew的位置. 这个具体的情况是,需要做一个SlidingMenu的 ...
- Redis操作Set工具类封装,Java Redis Set命令封装
Redis操作Set工具类封装,Java Redis Set命令封装 >>>>>>>>>>>>>>>>& ...
- Redis操作List工具类封装,Java Redis List命令封装
Redis操作List工具类封装,Java Redis List命令封装 >>>>>>>>>>>>>>>> ...
- Redis操作Hash工具类封装,Redis工具类封装
Redis操作Hash工具类封装,Redis工具类封装 >>>>>>>>>>>>>>>>>> ...
随机推荐
- vs常用插件之javsscript插件
1.JSEnhancements 折叠JS和CSS代码 http://visualstudiogallery.msdn.microsoft.com/0696ad60-1c68-4b2a-9646-4b ...
- MacOSX快捷键
[MacOSX快捷键] 关闭显示器:Shift + Ctrl + 退出键 休眠:Command + Option + 退出键 关机:Ctrl + Option + Command + 退出键 打开文件 ...
- JVM的内存管理机制
在做Java开发的时候常用的JVM内存管理有两种,一种是堆内存,一种是栈内存.堆内存主要用来存储程序在运行时创建或实例化的对象与变量,例如:我们通过new MyClass()创建的类MyClass的对 ...
- 用vagrant搭建一个自己的lnmp环境(一)
用vagrant搭建自己的lnmp环境 1.工具: a.vagrant b.virtual box c.linux服务器box(此处我使用centos 7.0) 2.安装完vagrant和virtua ...
- javaScript中"=="和"==="运算符的区别
相同点: 两个运算符均可用于比较两个值是否相等,可允许操作任意类型的操作数,如果操作数相等则返回true,否则返回false. 不同点: "==="运算符也称为严格相等运算符,它用 ...
- Web服务器与Web系统发布
在讨论Web系统发布之前,我们先来辨析两个概念:服务器.Web服务器. 通常,我们说的服务器,是一台提供服务的计算机,是硬件概念.这台主机有其IP地址,有服务端口,我们要访问时,就是通过IP地址唯一地 ...
- 使用spring.net 1.3.2框架部署在虚拟目录上发生错误
如果你的网站使用了Spring.net 1.3.2,并部署在IIS的虚拟目录上,那么将会出现如下错误: The virtual path '/currentcontext.dummy' maps ...
- 配置Outlook Anywhere2010
防火墙只需要开放CAS的443端口,其他硬件防火墙也是如此,不需要开放其他额外端口(80也没有必要开通,如果都使用https的话) 1.CAS:服务器配置-申请证书(内部.外部CAS名称)2.CAS: ...
- ZooKeeper是什么?
What is ZooKeeper? (译:什么是ZooKeeper?) ZooKeeper is a centralized service for maintaining configuratio ...
- android学习记录(十三)Task 和 Activity 回退栈操作。
首先说一下Task是一个什么概念吧:Task是一个包括activity的列表.没 错.简单的说就是依照启动的先后来排队的一个队列.Back Stack.就是回退栈的意思:那么有什么用?Back Sta ...