CALayer anchorPoint 锚点始终为(0,0)
objc.io 学习 摘自原处修改
对层的属性详细了解可见这里
@interface ClockFace : CAShapeLayer
@property (nonatomic, strong) NSDate *time;
@end
@interface ClockFace ()
@property (nonatomic, strong) CAShapeLayer *hourHand;
@property (nonatomic, strong) CAShapeLayer *minuteHand;
@end
@implementation ClockFace
- (instancetype)init {
if (self = [super init]) {
self.backgroundColor = [UIColor grayColor].CGColor;
self.bounds = CGRectMake(0, 0, 200, 200);
self.position = CGPointMake(520, 150);
self.path = [UIBezierPath bezierPathWithOvalInRect:self.bounds].CGPath;
// self.anchorPoint = CGPointMake(0, 0);
self.fillColor = [UIColor whiteColor].CGColor;
self.strokeColor = [UIColor blackColor].CGColor;
self.lineWidth = 4;
self.hourHand = [CAShapeLayer layer];
self.hourHand.bounds = CGRectMake(0, 0, 4, 70);//若未设置bounds,anchorPoint实际指向始终为{0,0},代表左上角;默认为{0.5,0.5}代表中心点随着position属性偏移
self.hourHand.path = [UIBezierPath bezierPathWithRect:self.hourHand.bounds].CGPath;
self.hourHand.lineWidth = .5f;
self.hourHand.strokeColor = [UIColor blackColor].CGColor;
self.hourHand.fillColor = [UIColor yellowColor].CGColor;
self.hourHand.anchorPoint = CGPointMake(1, 1);
self.hourHand.position = CGPointMake(102, 100);
[self addSublayer:self.hourHand];
self.minuteHand = [CAShapeLayer layer];
self.minuteHand.bounds = CGRectMake(0, 0, 2, 90);
self.minuteHand.path = [UIBezierPath bezierPathWithRect:self.minuteHand.bounds].CGPath;
self.minuteHand.lineWidth = .5f;
self.minuteHand.strokeColor = [UIColor blackColor].CGColor;
self.minuteHand.fillColor = [UIColor yellowColor].CGColor;
self.minuteHand.anchorPoint = CGPointMake(1, 1);
self.minuteHand.position = CGPointMake(101, 100);
[self addSublayer:self.minuteHand];
}
return self;
}
- (void)setTime:(NSDate *)time {
_time = time;
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [calendar components:NSCalendarUnitHour | NSCalendarUnitMinute fromDate:time];
self.hourHand.affineTransform = CGAffineTransformMakeRotation(components.hour / 12.0 * 2.0 * M_PI);
self.minuteHand.affineTransform = CGAffineTransformMakeRotation(components.minute / 60.0 * 2.0 * M_PI);
}

CALayer anchorPoint 锚点始终为(0,0)的更多相关文章
- 网站开启https后加密协议始终是TLS1.0如何配置成TLS1.2?
p { margin-bottom: 0.1in; line-height: 120% } 网站开启https后加密协议始终是TLS1.0如何配置成TLS1.2? 要在服务器上开启 TLSv1.,通常 ...
- 数据可视化-EChart2.0.0使用中遇到的2个问题
之前项目中都是使用FusionChart和HighChart,基本都是没有购买商业许可.然后现在开发的系统需要交付给客户使用.所以现在图表控件不能直接使用FusionChart和HighChart,通 ...
- 解决ListView 跟ScroolView 共存 listItem.measure(0, 0) 空指针
在网上找到ListView 和ScroolView 共存的方法无非是给他每个listview 重新增加高度,但是android 的设计者始终认为这并不是一种好的实现方法.但是有的时候有必须要用这种蛋疼 ...
- 解决ListView 和ScroolView 共存 listItem.measure(0, 0) 空指针
在网上找到ListView 和ScroolView 共存的方法无非是给他每个listview 重新增加高度,但是android 的设计者始终认为这并不是一种好的实现方法.但是有的时候有必须要用这种蛋疼 ...
- Java 获取客户端ip返回127.0.0.1问题
Java开发中使用 request.getRemoteAddr 获取客户端 ip ,返回结果始终为127.0.0.1.原因是服务器使用了nginx反向代理. 解决办法:在nginx配置文件nginx. ...
- Redis-5.0.0集群配置
版本:redis-5.0.0 参考:http://redis.io/topics/cluster-tutorial. 集群部署交互式命令行工具:https://github.com/eyjian/re ...
- hadoop3.0.0测验
下载地址: hadoop: http://mirrors.hust.edu.cn/apache/hadoop/common/hadoop-3.0.0/ 准备工作: 1.master节点与其他节点需要建 ...
- NPOI2.2.0.0实例详解(十一)—向EXCEL插入图片
--------------------- 本文来自 天水宇 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/xxs77ch/article/details/50553 ...
- WPF 自定义 MessageBox (相对完善版 v1.0.0.6)
基于WPF的自定义 MessageBox. 众所周知WPF界面美观.大多数WPF元素都可以简单的修改其样式,从而达到程序的风格统一.可是当你不得不弹出一个消息框通知用户消息时(虽然很不建议在程序中频繁 ...
随机推荐
- angularjs指令系统系列课程(3):替换replace,内容保留transclude,作用方式restrict
这一节我们主要看一下replace,transclude,restrict这三个参数 1.replace 可取值:bool 默认为:true 对于replace属性,设置为false表示原有指令标识不 ...
- 虚拟现实外包公司—焰火工坊CTO团队外包难把VR真正做起来,讲故事可能将伤害产业链
CTO王明杨,带着他的焰火工坊,正在为自家VR播放器和系统的上线做最后准备.不少投资机构,有传言称包括小米在内巨头都试图染指VR领域,而上月上市的暴风影音正是倚靠VR的概念成功助推了其高股价.对此,王 ...
- [重要公告] 关于禁止发布Windows系统及非法激活软件的通知
Skyfree 发表于 2013-11-15 09:45:17 https://www.itsk.com/thread-306891-1-1.html 接微软方面法务通知,要求删除涉及发布Win8/8 ...
- unity-点乘和叉乘的应用
http://blog.csdn.net/oskytonight/article/details/38900087 点乘:两个向量点乘得到一个标量 ,数值等于两个向量长度相乘后再乘以二者夹角的余弦值 ...
- spring框架学习(六)AOP
AOP(Aspect-OrientedProgramming)面向方面编程,与OOP完全不同,使用AOP编程系统被分为方面或关注点,而不是OOP中的对象. AOP的引入 在OOP面向对象的使用中,无可 ...
- OpenGL利用模板测试实现不规则裁剪
本文是原创文章,如需转载,请注明文章出处 在游戏开发中,经常会有这样的需求:给定一张64x64的卡牌素材,要求只显示以图片中心为圆点.直径为64的圆形区域,这就要用到模板测试来进行不规则裁剪. 实现不 ...
- mysql安装innodb插件
可以用 show engines;或者show plugins;来查看mysql> show plugins;+------------+--------+----------------+-- ...
- js倒计时跳转页面
var t=10; setInterval(function refer(){ if(t>0){ document.getElementById("em").innerHTM ...
- [转]IE8兼容Jquery.validate.js兼容问题
只需在jquery.validate.js 文件中在446行附近找到return $([]).add(this.currentForm.elements).filter(":input&qu ...
- OpenBSD内核之引导MBR
MBR的介绍网上很多,没错,就那个最后以0x55AA结尾的512字节的引导块,OpenBSD提供了引导MBR实现:OpenBSD在x86上的引导过程为MBR --> PBR --> boo ...