Using rotation to implement the clock (IOS) by Wusheying
- (void) Viewdidload {
[SuperViewdidload];
Self.Secondhand.Layer.Anchorpoint = Cgpointmake(. 5,. 9);
Self.Minutehand.Layer.Anchorpoint = Cgpointmake(. 5,. 9);
Self.Hourhand.Layer.Anchorpoint = Cgpointmake(. 5,. 9);
Self.Timer = [NstimerScheduledtimerwithtimeinterval:1.0Target: Selfselector:@selector(tick)UserInfo:Nilrepeats:YES];
[ SelfTick];
}
- (void) Tick {
Nscalendar*calendar = [[NscalendarAlloc]Initwithcalendaridentifier:Nsgregoriancalendar];
Nsuintegerunits =Nshourcalendarunit |Nsminutecalendarunit |Nssecondcalendarunit;
nsdatecomponents*components = [Calendar Components: UnitsFromDate:[NSDateDate]];
CGFloatHoursangle = (components.Hour /12.0) *M_PI *2.0;
CGFloatMinsangle = (components.minute /60.0) *M_PI *2.0;
CGFloatSecsangle = (components.Second /60.0) *M_PI *2.0;
Self.Hourhand.Transform = cgaffinetransformmakerotation(Hoursangle);
Self.Minutehand.Transform = cgaffinetransformmakerotation(Minsangle);
Self.Secondhand.Transform = cgaffinetransformmakerotation(secsangle);}
Using rotation to implement the clock (IOS)