- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章iOS时钟开发案例分享由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家介绍了ios时钟开发过程,供大家参考,具体内容如下 。
思路就是利用calayer的隐式动画来实现。因为uiview的非根层也就是手动创建的layer在其属性发生变化时会默认会产生动画效果,这些属性也叫作可动画属性。比如bounds、backgroundcolor、position.
时钟里面表盘就是一个uiview,而三根针就是三个手动创建的layer.
先在storyboard上弄一个uiimageview,设置表盘图片 。
然后在viewdidload中初始化三根针,并设置定时器,获取当前时间,将当前时间对应的时针分针秒针分别指向对应的角度.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
//
// viewcontroller.m
// 时钟效果
//
// created by daniel on 16/4/7.
// copyright © 2016年 daniel. all rights reserved.
//
#define kclockwh _clockview.bounds.size.width
//一秒钟秒针转多少度
#define preseconda 6
//一分钟分针转多少度
#define preminutea 6
//一小时时针转多少度
#define prehoura 30
//每分钟时针转多少度
#define prehourminute 0.5
//每秒钟分针转多少度
#define preminutesecond 0.1
#define angle2raditon(a) ((a) / 180.0 * m_pi)
#import "viewcontroller.h"
@interface viewcontroller ()
@property (weak, nonatomic) iboutlet uiimageview *clockview;
/** 秒针 */
@property(nonatomic, strong) calayer *secondl;
/** 分针 */
@property(nonatomic, strong) calayer *minutel;
/** 时针 */
@property(nonatomic, strong) calayer *hourl;
@end
@implementation viewcontroller
- (
void
)viewdidload {
[super viewdidload];
//添加时针
[self setuphourlayer];
//添加分针
[self setupminutelayer];
//添加秒针
[self setupsecondlayer];
//添加定时器
[nstimer scheduledtimerwithtimeinterval:1 target:self selector:@selector(timechange) userinfo:nil repeats:yes];
//开始运行时就获取时间,这样在启动时就不会有停顿的感觉
[self timechange];
}
- (
void
)timechange {
//获取当前系统时间
nscalendar *calendar = [nscalendar currentcalendar];
nsdatecomponents *cmp = [calendar components:nscalendarunitsecond | nscalendarunitminute | nscalendarunithour fromdate:[nsdate date]];
//获取秒
nsinteger second = cmp.second;
//获取分
nsinteger minute = cmp.minute;
//获取小时
nsinteger hour = cmp.hour;
//计算秒针转多少度
cgfloat seconda = second * preseconda;
//计算分针转多少度
cgfloat minutea = minute * preminutea + second * preminutesecond;
//计算时针转多少度
cgfloat houra = hour * prehoura + minute * prehourminute;
//旋转秒针
_secondl.transform = catransform3dmakerotation(angle2raditon(seconda), 0, 0, 1);
//旋转分针
_minutel.transform = catransform3dmakerotation(angle2raditon(minutea), 0, 0, 1);
//旋转时针
_hourl.transform = catransform3dmakerotation(angle2raditon(houra), 0, 0, 1);
}
#pragma mark - 初始化时针
- (
void
)setuphourlayer {
calayer *hourl = [calayer layer];
//设置秒针背景色
hourl.backgroundcolor = [uicolor blackcolor].cgcolor;
//设置秒针锚点
hourl.anchorpoint = cgpointmake(0.5, 1);
//设置秒针锚点在父控件的位置
hourl.position = cgpointmake(kclockwh * 0.5, kclockwh * 0.5);
hourl.cornerradius = 4;
//设置秒针bounds
hourl.bounds = cgrectmake(0, 0, 4, kclockwh * 0.5 - 40);
//把秒针添加到clockview图层上
[_clockview.layer addsublayer:hourl];
_hourl = hourl;
}
#pragma mark - 初始化分针
- (
void
)setupminutelayer {
calayer *minutel = [calayer layer];
//设置秒针背景色
minutel.backgroundcolor = [uicolor blackcolor].cgcolor;
//设置秒针锚点
minutel.anchorpoint = cgpointmake(0.5, 1);
//设置秒针锚点在父控件的位置
minutel.position = cgpointmake(kclockwh * 0.5, kclockwh * 0.5);
minutel.cornerradius = 4;
//设置秒针bounds
minutel.bounds = cgrectmake(0, 0, 4, kclockwh * 0.5 - 20);
//把秒针添加到clockview图层上
[_clockview.layer addsublayer:minutel];
_minutel = minutel;
}
#pragma mark - 初始化秒针
- (
void
)setupsecondlayer {
calayer *secondl = [calayer layer];
//设置秒针背景色
secondl.backgroundcolor = [uicolor redcolor].cgcolor;
//设置秒针锚点
secondl.anchorpoint = cgpointmake(0.5, 1);
//设置秒针锚点在父控件的位置
secondl.position = cgpointmake(kclockwh * 0.5, kclockwh * 0.5);
//设置秒针bounds
secondl.bounds = cgrectmake(0, 0, 1.5, kclockwh * 0.5 - 20);
//把秒针添加到clockview图层上
[_clockview.layer addsublayer:secondl];
_secondl = secondl;
}
@end
|
效果图:
以上就是本文的全部内容,希望对大家学习ios程序设计有所帮助.
最后此篇关于iOS时钟开发案例分享的文章就讲到这里了,如果你想了解更多关于iOS时钟开发案例分享的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我需要一些说明。我可以直接写入 /dev/port 以直接访问并行端口并且它工作正常(我可以打开插入端口连接器的 LED)。但是,我想我可以用 /dev/mem 做同样的事情? (http://tld
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我使用 Visual C++ 和 Win32 API 学习了 Windows 编程。如今,似乎大多数应用程序都是使用 C# 在 .NET 中开发的。我知道大多数时候 native 代码和托管代码之间没
请耐心等待。我正在制作一个 java 控制台,类似于此处找到的 DragonConsole https://code.google.com/p/dragonconsole/ 。一切都按计划进行,但我想
关闭。这个问题需要更多 focused .它目前不接受答案。 想要改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭5年前。 Improve this que
Django 的开发服务器表现得很奇怪。访问它的浏览器在加载时卡住,任何退出它的尝试都不起作用。当我点击 control c看似相当,但实际上仍在运行。让它退出的唯一方法是重新启动我的电脑,这很令人沮
我正在使用 Flash Develop,并且创建了一个 ActionScript 3.0 项目。它启动并读取一个 xml 文件,其中包含图像的 url。我已将 url 保留在与 swf 相同的文件夹中
是否可以根据其 website 上提供的规范开发 AUTOSAR BSW 堆栈(例如用于 CAN 通信)?不购买任何昂贵的供应商工具?可以遵循哪些步骤?我被要求探索这种可能性。 最佳答案 是和否。工具
有人知道如何用音频文件的内容覆盖 iPhone 麦克风吗? 想象一个场景,您正在通话,并且想要播放一些简短的音频让其他人听到。 因此,有必要将麦克风(硬件)置于保持状态,并使用委托(delegate)
我遇到了这个问题,我的应用程序出现 EXC_BAD_ACCESS 错误并卡住/停止。我使用模拟器的“向左旋转”和“向右旋转”选项来模拟方向变化行为。导致此错误的可能原因有哪些?由于我没有获得有关错误的
我有超过 1 台 Mac,我想在所有这些 Mac 上进行开发。我知道我需要在每台机器上同步我的手机,但这是我遇到的最小的问题。看起来我无法在手机上运行应用程序,除了在其中之一上开发的应用程序。 是否有
在手机上测试时,我的应用程序在特定点崩溃。控制台显示此消息 Tue Jan 27 15:47:14 unknown SpringBoard[22] : Application com.myprof.
我有一个案例,我从服务器获取信息。我的应用程序有一个选项卡栏和导航按钮。我希望应用程序显示进度指示器并禁用所有其他控件,以便用户在从服务器提取数据时无法跳转。我怎样才能实现这个目标? 我想到的一种方法
有时,当我尝试“构建”/编译下载的源代码时,我会收到以下警告: ld: warning: directory '/Volumes/Skiiing2/CD/ViewBased/Unknown Path/
我无法在 Apple 文档中找到关于开发和分发配置之间差异的明确解释。我目前正在使用开发配置在我的 iPhone 上进行开发和测试。我打算将该应用程序分发到我的 Beta 测试中,我想知道: 我需要使
我在使用 SharePoint 时遇到的最大挑战之一是它不能很好地适应典型的项目环境,其中至少包含开发和生产环境。我遇到的最多的问题是内容和列表是如此紧密地耦合在一起,以至于如果不在生产环境中执行内容
我失败了fist step让 Eclipse(对我来说是全新的)为 ARM 开发做好准备。 我在 Windows 10 中安装了 Eclipse。我想我应该安装 xpm,但我不知道在哪里输入此命令:
首先,我告诉你-我是编码新手 我正在使用vs代码来学习c++,它不会产生像dev c++或codeblocks这样的调试器。我看了一些视频,其中我们必须编辑json文件,这对于初学者来说非常复杂。有人
我失败了fist step让 Eclipse(对我来说是全新的)为 ARM 开发做好准备。 我在 Windows 10 中安装了 Eclipse。我想我应该安装 xpm,但我不知道在哪里输入此命令:
我开发了一个 Ionic 应用程序(iOS 和 Android 的混合)。我有 Xcode 8.3.3 并购买了一年的 Apple Developer Program 订阅。 我不想测试我的应用并将其
我是一名优秀的程序员,十分优秀!