有模拟时钟的 iPhone 代码示例吗?
有兴趣创建自己的模拟时钟应用程序 - 有人知道一些实现模拟时钟的示例项目/代码吗? (即不是数字时钟)。理想情况下使用自定义背景和自定义时/分针作为图像?
我注意到以下链接存在,但是希望有一些更具体的内容来匹配我正在做的事情(背景图像,时针/分针的图像): 示例代码
Interested in creating by own analog clock application - anyone know of some example project/code that implements an analogue clock? (i.e. not a digital clock). Ideally with a custom background, and custom hour/minute hands as images?
I note that the following link exists, however was hoping for something just a little more specific to matching what I'm doing (background image, images for the hour/minute hands): Example Code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建背景图像以及每只指针的图像(秒、分钟、小时 - 无论您想要什么)。每个图像必须与时钟本身一样大,但不能缩放。将手放在 12 标记处。用手使图像中的其他所有内容变为 Alpha。
现在,使用图像视图/孔将所有图像放在视图中的同一位置。您的时钟应该显示 12 点。
在您的代码中,创建一个由计时器每秒调用的方法。此方法将旋转视图,以便指针旋转到正确的位置。您可以使用
NSView
或UIView
的transform属性。注意: Apple对此进行了详细解释:"平移、缩放和旋转视图”。示例:
只需更改图像,您就可以更改外观。
Create a background image, and images for each of the hands (seconds, minutes, hours — whatever you want). Every image must be as big as the clock itself, but do not scale. Put the hands at the 12 mark. Make everything else alpha in the images with the hands.
Now, put all images at the same location in your view with an image view/well. Your clock should read 12 o'clock.
In your code, create a method which will be called every second by a timer. This method will rotate the views so that the hands are rotated to the correct position. You can use the transform property of
NSView
orUIView
.Note: Apple explains this in detail: "Translating, Scaling, and Rotating Views". An example:
Just by changing the images, you can change the appearance.