IOS开发之——时钟(94),android界面设计规范

  • 创建秒针CALayer

  • 设置秒针的锚点(anchorPoint),位置(position),尺寸(长度),颜色

2.2 分针

  • 计算出时钟ImageView的大小(宽度和高度)

  • 创建分针CALayer

  • 设置分针的锚点(anchorPoint),位置(position),尺寸(长度),颜色

2.1 时针

  • 计算出时钟ImageView的大小(宽度和高度)

  • 创建时针CALayer

  • 设置时针的锚点(anchorPoint),位置(position),尺寸(长度),颜色

三 更新时间


  • 获取日历对象,并根据日历对象获取NSDateComponents

  • 根据NSDateComponents分别获取秒数/分数/小时数

  • 再根据当前的秒数/分数/小时数和每秒/每分/每小时的选择角度,计算出应偏移的度数

  • CATransform3DMakeRotation执行旋转

四 示例


4.1 代码

#import “ViewController.h”

//每秒秒针转6度

#define perSecendA 6 //360/60

//每分钟分针转6度

#define perMinuteA 6 //360/60

//每小时时针转多少度

#define perHourA 30 //360/12

//每分钟时针转6度

#define perMinuteHourA 0.5 //30/60

#define angle2radian(x) ((x)/180.0 * M_PI)

@interface ViewController ()

{

CALayer *_second;

CALayer *_minute;

CALayer *_hour;

}

@property (weak, nonatomic) IBOutlet UIImageView *clockView;

@end

@implementation ViewController

  • (void)viewDidLoad {

[super viewDidLoad];

//1-添加秒针

[self addSecond];

//2-添加分针

[self addMinute];

//3-添加时针

[self addHour];

//创建定时器

[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(update) userInfo:nil repeats:YES];

[self update];

}

//添加时针

-(void)addHour

{

CGFloat imageW=_clockView.bounds.size.width;

CGFloat imageH=_clockView.bounds.size.height;

//1.添加分针

CALayer *hour=[CALayer layer];

//2.添加锚点

hour.anchorPoint=CGPointMake(0.5, 1);

//3.设置位置

hour.position=CGPointMake(imageW0.5, imageH0.5);

//4.设置尺寸

hour.bounds=CGRectMake(0, 0, 4, imageH*0.5-50);

//5.设置背景色

hour.backgroundColor=[UIColor blackColor]

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

.CGColor;

hour.cornerRadius=5;

//6.添加到图层上

[_clockView.layer addSublayer:hour];

_hour=hour;

}

//添加分针

-(void)addMinute

{

CGFloat imageW=_clockView.bounds.size.width;

CGFloat imageH=_clockView.bounds.size.height;

//1.添加分针

CALayer *minute=[CALayer layer];

//2.添加锚点

minute.anchorPoint=CGPointMake(0.5, 1);

//3.设置位置

minute.position=CGPointMake(imageW0.5, imageH0.5);

//4.设置尺寸

minute.bounds=CGRectMake(0, 0, 2, imageH*0.5-30);

//5.设置背景色

minute.backgroundColor=[UIColor blackColor].CGColor;

//6.添加到图层上

[_clockView.layer addSublayer:minute];

_minute=minute;

}

//添加秒针

-(void)addSecond

{

CGFloat imageW=_clockView.bounds.size.width;

CGFloat imageH=_clockView.bounds.size.height;

//1.添加秒针

CALayer *second=[CALayer layer];

//2.添加锚点

second.anchorPoint=CGPointMake(0.5, 1);

//3.设置位置

second.position=CGPointMake(imageW0.5, imageH0.5);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值