iOS development-cgaffinetransformmakerotation changes the central solution

Source: Internet
Author: User

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
  1. NSDate *today = [nsdate Date];
  2. Nscalendar *calendar = [Nscalendar Currentcalendar];
  3. Unsigned flags = Nshourcalendarunit | Nsminutecalendarunit | Nssecondcalendarunit;
  4. nsdatecomponents *todaycomponents = [Calendar components:flags
  5. Fromdate:today];
  6. int hour = [todaycomponents hour];
  7. int min = [todaycomponents minute];
  8. int sec = [todaycomponents second];
  9. float Finehour = (hour% 12) + min/60. 0;
  10. Hourhand. Transform = cgaffinetransformmakerotation (m_pi * 22 * finehour/ 12. 0);
  11. Minutehand. Transform = cgaffinetransformmakerotation (m_pi * 22 * min/ 60. 0);
  12. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.