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元素都可以简单的修改其样式,从而达到程序的风格统一.可是当你不得不弹出一个消息框通知用户消息时(虽然很不建议在程序中频繁 ...
随机推荐
- B/S网站中IE6兼容问题
在HTML中定义的样式,部分样式在IE7以前的版本中的效果是不同的,所以需要在网页中定义让浏览器以IE8的模式启动. 在HEAD中定义标签meta如下: <meta http-equiv=&qu ...
- CSS垂直居中的方法
前端开发过程中,水平垂直居中是比较常用的.下面直接开门见山,看看不同方法实现垂直居中的各自优点和其不足之处. 1.将“line-height”和“height”设置成一致 这种方法用来实现单行垂直居中 ...
- C语言多文件编译
fun.c #include <stdio.h> int fun1(){ printf("The first function!\n"); return 0; } in ...
- 第一次写Web API接口
API是什么?只知道是网络接口,具体怎么写?不会!如何调用?不会!那怎么办? 第一次的经历~~ 需求:为其他项目提供一个接口 功能:为项目提供询盘信息和商家信息,格式为Json字符串 拿过来,就开始做 ...
- iOS开发 二维码生成
基于libqrencode的二维码生成 + (void)drawQRCode:(QRcode *)code context:(CGContextRef)ctx size:(CGFloat)size { ...
- IntelliJ IDEA中Maven项目的默认JDK版本
在IntelliJ IDEA 15中使用Maven时,IDEA将默认的编译版本.源码版本设置为jdk5.编译项目的时候出现警告:"Warning:Java: 源值1.5已过时, 将在未来所有 ...
- ftp put本地文件至ubuntu服务器报错
起因:我想把本地下载的安装包上传至服务器. 由于Mac的ftp图形化客户端还没找着合适的,就想着用命令也是一样的. 但是又进坑了. 下载能够正常运行: ftp> get 2.jpg /Users ...
- JS中循环绑定遇到的问题及解决方法
本文是原创文章,如需转载,请注明文章出处 在工作中,有时会有这样的需求:在一个页面上添加了6个按钮,然后分别为他们绑定点击事件监听器,当点击按钮1时,输出1,当点击按钮2时,输出2. 循环绑定代码如下 ...
- Java中的方法应用
一.如何定义java中的方法 所谓方法,就是用来解决一类问题的代码的有序组合,是一个功能模块. 语法: 1. 访问修饰符:方法允许被访问的权限范围, 可以是 public.protected.priv ...
- 【NodeJS线程】Boss和他的职员们
>>>[说明]还是一如既往的,这篇文章是从我的个人博客里挪过来的.原文参见:http://www.jscon.co/coding/frontend/nodejs_fork_child ...