IOS development-CGAffineTransformMakeRotation changed the central solution, cgaffinetransform

Source: Internet
Author: User

IOS development-CGAffineTransformMakeRotation changed the central solution, cgaffinetransform

Poor Dad. It took two hours to solve the problem. Annoying ..


When I wrote a clock demo today, CGAffineTransformMakeRotation was used for clockwise rotation. the rotation of an image is centered on the image itself, that is, its center is fixed during the rotation process. The effect is the same as that of our hour hands.

For example, the Code for rotating the hour hand, minute hand, and second hand below me:

    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 * 2 * fineHour / 12.0);    minuteHand.transform = CGAffineTransformMakeRotation(M_PI * 2 * min / 60.0);    secondHand.transform = CGAffineTransformMakeRotation(M_PI * 2 * sec / 60.0);

The code is okay.

However, when running, it is found that the center has changed during the rotation process. Obvious displacement...

After a long time, it turned out to be an automatic layout.

Solution:

1. Disable Automatic Layout.

2. You should set the constraints of the center, rather than the constraints of the edge location.



Solved. Sleeping ..


Control rotation in ios development

Slider. transform = CGAffineTransformMakeRotation (90 * M_PI/180 );

Where is the developer version of IOS 8 located on the Developer Center website? How to download?

Login .apple.com/and click member center above.

Click iOS in Technical Resources and Tools.

Then we can see the iOS 8 beta. However, you need to sign an agreement first.




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.