开发者

Iphone app - How to show the digital clock with current time

Hello all I am working an iphone app where I need to show the current time in a watch That is there is a watch which displays the static time or static image . Then we need to find the current time then move all the hrs,mins ,seconds pins such tht they should set to their time. Do u have any ideas to do this Thanks Everyone Here is my code:

//Calculate angles: float minutesAngle = (0/60)*360; float hoursAngle = (10/12)*360;

//Begin the animation block
[UIView beginAnimations:@"moveHands" context:nil];
[UIView setAnimationDuration:0.5];
minsImageView.transform = CGAffineTransformRotate(minsImageView.transform, minutesAngle);
hoursImageView.transform = CGAffineTransformRotate(hoursImageView.transform, hoursAngle);
[UIView commitAnimations];

where as minsImageView ,hoursImageView are the imageViews 开发者_运维技巧set in the XIB who shows the static image

But its not effecting at all..


Once you have individual time values (it sounds like you've figured this out already) you can position your hands as needed.

This means it's time to brush up on your math skills. I think this'll give you a start:

A circle has 360 degrees in it. This means that for whatever time unit we get, we divide by the maximum value of that time unit to get a fraction and multiply the result by 360 (instead of 100 like a percentage) to get our number of degrees.

So, if we had 23 seconds:

23/60 = 3.8333
3.8333 x 360 = 138 degrees

Now we know how many degrees to rotate our object. I would get a designer to make you some nice hand images and put them in UIImageViews. Then, you can rotate them around their origins like so:

secondHandImage.transform = CGAffineTransformMakeRotate(secondAngle);

Good luck :)

EDIT: Let's assume that our hands are on 10:10. If we wanted to move them to 01:00 we would do something like the following. Tweak it as needed.

//Calculate angles:
float minutesAngle = (0/60)*360;
float hoursAngle = (10/12)*360;

//Begin the animation block
[UIView beginAnimations:@"moveHands" context:nil];
[UIView setAnimationDuration:0.5];
minutesHand.transform = CGAffineTransformRotate(minutesHand.transform, minutesAngle);
hoursHand.transform = CGAffineTransformRotate(hoursHand.transform, hoursAngle);
[UIView commitAnimations];


If you're trying to show a digital clock, your life is SOOOO much easier than my previous answer related to analog clocks.

Create images with the numbers 0-9 and put them in your bundle. Have four UIImageViews in your UI in this configuration:

[][]:[][]

[ ] = UIImageVIew

Then, you can simply change the images in each slot to reflect the time. If you use transparent backgrounds and high resolution graphics, you can create really convincing effects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜