通过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工具类封装 >>>>>>>>>>>>>>>>>> ...
随机推荐
- 内存中的static、const实现形式
最近在考虑下半年找工作的事情,看了不少面试题目,其中还是蛮有收获的,把基础好好复习了一遍.比如这个题目,static.const现形式,static和const类型的变量在写程序的时候也写了很多,不过 ...
- SKAction
[SKAction] 1.Every action is an opaque object that describes a change you want to make to the scene. ...
- 全球各大运营商黑莓ROM官网下载链接汇总
全球各大运营商黑莓ROM官网下载链接汇总: 先来关于8830的. 4.2.2.196的rom 8830EFS_PBr4.2.2_rel365_PL3.0.0.85_A4.2.2.196_Sprint ...
- WinHTTP Web Proxy Auto-Discovery Service
下面是网上搜集的,个人没有做测试,----------------------------- WinHTTP Web Proxy Auto-Discovery Service 服务成功发送一个 开始 ...
- CTE初识
微软从SQl2005起引入了CTE(Common Table Expression)以强化T-SQL.这是一个类似于非持久视图的好东西. 正常的SQL语句: select * from person. ...
- HDU 4667 Building Fence
题意: 给n个圆和m个三角形,且保证互不相交,用一个篱笆把他们围起来,求最短的周长是多少. 做法:--水过... 把一个圆均匀的切割成500个点,然后求凸包. 注意:求完凸包,在求周长的时候记得要把圆 ...
- Spring JTA应用JOTM & Atomikos II JOTM
上节建立了一个简单的Java Application以及所需要的数据库和数据表,本节将介绍JOTM在Spring中的配置. JOTM(Java Open Transaction Manager)是Ob ...
- 汇编语言程序入门实验二:在dos下建立子目录操作
汇编语言程序入门实验二:在dos下建立子目录操作 1,背景 在读此文,并读懂前,建议读者先阅读这两篇博客 1,在dos环境下汇编语言程序设计入门(输出hello world)和masm32的下载.安装 ...
- D. Green and Black Tea
先搞多的,搞到相等. (tmd上星期+上上星期简直是弱智,怎么也不会写,总是想着各种a/b,,,踢蹬) #include<bits/stdc++.h> #define lowbit(x) ...
- OC:Block语法、Block使用、Block实现数组排序
Block //定义一个求两个数最大值函数 int maxValue (int ,int); //函数的实现 int maxValue (int a, int b){ return a > b ...