Today, when writing a clock demo, the rotation of the hour hand is used to cgaffinetransformmakerotation, supposedly. The rotation of the image is anchored to the center of the image itself, that is, in the process of rotation, its center is fixed. It's the same as our hour hand.
For example, I have the following hour, minute, second hand rotation code:
[OBJC]View Plaincopy
- NSDate *today = [nsdate Date];
- Nscalendar *calendar = [Nscalendar Currentcalendar];
- Unsigned flags = Nshourcalendarunit | Nsminutecalendarunit | Nssecondcalendarunit;
- nsdatecomponents *todaycomponents = [Calendar components:flags
- Fromdate:today];
- int hour = [todaycomponents hour];
- int min = [todaycomponents minute];
- int sec = [todaycomponents second];
- float Finehour = (hour% 12) + min/60. 0;
- Hourhand. Transform = cgaffinetransformmakerotation (m_pi * 22 * finehour/ 12. 0);
- Minutehand. Transform = cgaffinetransformmakerotation (m_pi * 22 * min/ 60. 0);
- Secondhand. Transform = cgaffinetransformmakerotation (m_pi * 22 * sec/ 60. 0);
The code is no problem.
However, when running, it turns out that the center has changed during the rotation. There is a noticeable displacement ...
Toss for a while, originally is the automatic layout to engage the ghost. The egg hurts.
The solution:
1. Turn off automatic layout.
2. You should set the center constraint, not the edge position constraint.
iOS development-cgaffinetransformmakerotation changes the central solution