Iphone 应用程序 - 如何显示数字时钟和当前时间
大家好,我正在开发一个 iPhone 应用程序,我需要在手表中显示当前时间,即有一个手表可以显示静态时间或静态图像。然后我们需要找到当前时间,然后移动所有小时、分钟、秒针,以便将它们设置为时间。 你有什么想法吗 谢谢大家 这是我的代码:
//计算角度: 浮动分钟角度 = (0/60)*360; 浮动小时角度 = (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];
其中 minsImageView 、hoursImageView 是 XIB 中设置的 imageView,用于显示静态图像
,但它根本没有效果。
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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一旦你有了单独的时间值(听起来你已经弄清楚了这一点),你就可以根据需要放置你的手。
这意味着是时候温习你的数学技能了。我想这会给你一个开始:
一个圆有 360 度。这意味着,对于我们得到的任何时间单位,我们除以该时间单位的最大值以获得一个分数,并将结果乘以 360(而不是像百分比一样的 100)以获得我们的度数。
所以,如果我们有 23 秒:
现在我们知道要旋转对象多少度。我会让设计师为你制作一些漂亮的手部图像并将它们放入 UIImageViews 中。然后,您可以围绕它们的原点旋转它们,如下所示:
祝您好运:)
编辑: 让我们假设我们的指针位于 10:10。如果我们想将它们移至 01:00,我们会执行如下操作。根据需要调整它。
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:
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:
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.
如果你想展示一个数字时钟,你的生活比我之前关于模拟时钟的答案要容易得多。
创建包含数字 0-9 的图像并将它们放入您的包中。在此配置中,您的 UI 中有四个 UIImageView:
[][]:[][]
[ ] = UIImageVIew
然后,您可以简单地更改每个插槽中的图像以反映时间。如果您使用透明背景和高分辨率图形,您可以创建真正令人信服的效果。
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.