手上有UIImages的模拟时钟? [英] Analog clock with UIImages for hands?

查看:87
本文介绍了手上有UIImages的模拟时钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在iPhone SDK中制作模拟时钟。但是,我希望时钟的手是自定义图像而不是像本教程中那样绘制的正方形: http://iphone-dev-tips.alterplay.com/2010/03/analog-clock-using-quartz-core.html

I want to know how to make an analog clock in iPhone SDK. However, I want the hands of the clock to be custom images and not squares drawn over like in this tutorial: http://iphone-dev-tips.alterplay.com/2010/03/analog-clock-using-quartz-core.html

该教程的问题在于时钟指针是用Quarzt Core绘制的。只要手可以定制,我就可以了。以这种方式制作模拟时钟最简单的方法是什么?

The problem with that tutorial is that the clock hands are drawn with Quarzt Core. I'm okay with that as long as the hands could be custom. What would be the easiest way to make an Analog Clock this way?

推荐答案

用CALayers做。通过这种方式更轻松,性能更好。

Do it with CALayers. is WAY much easier and performance is better this way.

CALayer *handLayer = [CALayer layer];
handLayer.contents = (id)[UIImage imageNamed:@"hand.png"].CGImage;
handLayer.anchorPoint = CGPointMake(0.5,0.0)];
[myview.layer addSublayer:handLayer];

//i.e.: if handLayer represents the seconds hand then repeat this every second ;)
handLayer.transform = CGAffineTransformMakeRotation (angle); //set the angle here


更新:

我写了使用CALayers 的ClockView示例,也许您觉得它很有用。

I wrote a ClockView sample using CALayers, maybe you find it useful.

这篇关于手上有UIImages的模拟时钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆