注意:- 在 .h 文件中声明
@property(nonatomic , weak) NSTimer *timer;
@property (weak, nonatomic) IBOutlet UIImageView *imgViewClock; //Image of Wall Clock
@property (weak, nonatomic) IBOutlet UIImageView *hourHandImgView; //Image of Hour hand
@property (weak, nonatomic) IBOutlet UIImageView *minuteHandImgView; //Image of Minute hand
@property (weak, nonatomic) IBOutlet UIImageView *secondHandImgView; //Image of Second hand
注意:- 在 .m 文件中声明
- (void)viewDidLoad {
[super viewDidLoad];
//Clock
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(tick) userInfo:nil repeats:YES];
[self tick];
}
//这里的assign(tick)方法
-(void)tick {
NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSUInteger units = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSDateComponents *Components = [calendar components:units fromDate:[NSDate date]];
CGFloat hours = (Components.hour / 12.0) * M_PI * 2.0;
CGFloat mins = (Components.minute / 60.0) * M_PI * 2.0;
CGFloat seconds = (Components.second / 60.0) * M_PI * 2.0;
self.hourHandImgView.transform = CGAffineTransformMakeRotation(hours);
self.minuteHandImgView.transform = CGAffineTransformMakeRotation(mins);
self.secondHandImgView.transform = CGAffineTransformMakeRotation(seconds);
}