我想知道如何在iPhone SDK中制作模拟时钟。但是,我希望时钟的指针是自定义图像,而不是像本教程中那样绘制的正方形:http://iphone-dev-tips.alterplay.com/2010/03/analog-clock-using-quartz-core.html
该教程的问题在于时钟指针是用 Quarzt Core 绘制的。只要手可以定制,我就可以接受。以这种方式制作模拟时钟的最简单方法是什么?
使用 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
UPDATE:
我写了一个使用 CALayers 的 ClockView 示例,也许你觉得它很有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)