通过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工具类封装 >>>>>>>>>>>>>>>>>> ...
随机推荐
- POJ 3177 Redundant Paths POJ 3352 Road Construction
这两题是一样的,代码完全一样. 就是给了一个连通图,问加多少条边可以变成边双连通. 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话,把双连通子图收缩为一个点,形成一颗树 ...
- beantool.map2Bean(map,obj)
- iOS 中self和super如何理解?
或许你理解self和super都是指的是类的对象 self指的是本类的对象,而super指的是父类的对象,但是事实情况呢,可能有些和你想象的不一样? 简单看下下面例子: @interface Pe ...
- PowerDesigner反向生成Mysql数据原型
PowerDesigner反向生成Mysql数据原型 注意事项: (1)JVM 要32位的. (2)需配置JAVA_HOME环境变量指向所需JVM. (3)需配置CLASSPATH环境变量执行 MyS ...
- 使用IBatisNet的网站,修改database.config无效的问题解决
这周五去客户那更新了一个使用了IBatisNet的Web项目,备份了项目.数据库之后,替换更新的文件(含bin目录)却报数据库连接错. 因为是接手的一个维护项目,加上交接有点问题,所以遇到问题只能自己 ...
- Innodb的事务与日志 & JTA事务
InnoDB引擎的行锁是通过加在什么上完成(或称实现)的?为什么是这样子的 通过 行多版本控制 MyISAM Innodb 事物支持 : 不支持 ...
- inpuy type=date
http://www.w3schools.com/html/html_form_input_types.asp http://caniuse.com/#feat=input-datetime 浏览器兼 ...
- Form时间交叉验证唯一性
*================================================== ** PROCEDURE: check_effcitive_utl Descr ...
- SRM 451 DIV 1 总结
250p:这次是有史以来做的最快的一次250p...看题花了两分钟,敲代码最多一分钟...太明显了题意~ 500p:这题水了...每次都这样...很显然用DP来做,不过前面状态表示有问题了...搞了好 ...
- xx.exe 中的 0x7c92e4df 处最可能的异常: 0xC0000008: An invalid handle was specified
今天遇到个超级奇怪的问题,昨天还好端端的程序,今天用VS打开后,在关闭主窗口的时候居然弹出错误提示:xx.exe 中的 0x7c92e4df 处最可能的异常: "0xC0000008: An ...