Any example iPhone code for an Analog Clock?

五迷三道 提交于 2020-01-05 02:50:09

问题


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


回答1:


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 or UIView.


Note: Apple explains this in detail: "Translating, Scaling, and Rotating Views". An example:

// M_PI/4.0 is one quarter of a half circle, or 45 degrees.
CGAffineTransform xform = CGAffineTransformMakeRotation(M_PI/4.0);
hourHandsImageView.transform = xform;

Just by changing the images, you can change the appearance.



来源:https://stackoverflow.com/questions/6499996/any-example-iphone-code-for-an-analog-clock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!