Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8653075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:27:23+00:00 2026-06-12T14:27:23+00:00

I’m trying to do simple rotations in Objective-C and there are a couple problems

  • 0

I’m trying to do simple rotations in Objective-C and there are a couple problems right off the bat. One thing is the inconsistency I get from CGAffineTransformRotate and how M_PI is inconsistent when used inside that function.

Suppose I do this, and attach it to a button. When I press it once it will rotate 180 degrees counterclockwise (good and follows the documentation) but when I press it again, it will rotate 180 clockwise even though the value is not negative. Changing M_PI to -M_PI does the exact same thing with no differences in the rotation:

[UIView animateWithDuration:secs delay:0.0 options:option
   animations:^{
      self.transform = CGAffineTransformRotate(self.transform, M_PI);   //Inconsistent
} completion:nil];

Now suppose I changed M_PI to 3.141593, which is the value that M_PI contains when I print it. Now, when I press the button, it works completely fine. Both times, it’ll rotate 180 degrees counter clockwise. When I change it to -3.141593, it will work completely good too, clockwise:

self.transform = CGAffineTransformRotate(self.transform, 3.141593);   //Works

When I play with it more, the behavior gets more weird.

Suppose I want to rotate 90 degrees (pi/2). M_PI now has the same behavior as using a value but the rotation is opposite to what it should be:

//Should be Clockwise but rotates CounterClockwise
self.transform = CGAffineTransformRotate(self.transform, -M_PI/2);  
self.transform = CGAffineTransformRotate(self.transform, -1.5707965); 

//Should be CounterClockwise but rotates Clockwise
self.transform = CGAffineTransformRotate(self.transform, M_PI/2);  
self.transform = CGAffineTransformRotate(self.transform, 1.5707965);

And if I want to rotate anything over 180 degrees(PI), the behavior is just to rotate the shortest route even though I specify a positive or negative rotation. When I rotate 360 Degrees (2PI), it doesn’t even rotate.

Why these things happen and what can I do to make it more consistent?
And a secondary question I have is how can I rotate things 270 and 360 degrees.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:27:24+00:00Added an answer on June 12, 2026 at 2:27 pm

    The problem is you can’t really control the rotation direction when using animateWithDuration. It will always take the shortest route. When rotating 180 degrees the behavior is undetermined because in theory there are 2 possibilities for the shortest route. This also explains why you can’t rotate more than 180 degrees. If you want to have more control over the animation or do more complex animations use a CAKeyframeAnimation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.