带有UIImages手的模拟时钟?

And*_*y B 4 iphone nstimer ios

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

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

nac*_*o4d 12

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

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
Run Code Online (Sandbox Code Playgroud)


更新:

使用CALayers编写了一个ClockView示例,也许您觉得它很有用.