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 7073037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:52:53+00:00 2026-05-28T05:52:53+00:00

I am working on an app that has a rotating image (the user tapps

  • 0

I am working on an app that has a rotating image (the user tapps and drags and the image rotates in a circle tracking their finger). What I am trying to keep track of is how many times the user makes a complete circle. An additional “hitch” is that I also need to know if the user is circling clockwise vs counter clockwise.

Here is the Code that is rotating the image… Please feel free to request additional information.

   - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchPoint = [touch locationInView:self.view];

    long double rotationNumber = atan2(touchPoint.y - originY, touchPoint.x - originX);

    totalRotationCount ++;

    schedulingWheel.transform = CGAffineTransformMakeRotation(rotationNumber);

    offset = (rotationNumber * 100)/14;

    dateRibbon.center = CGPointMake(offset, 24);  
}

Thanks for the help!

  • 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-05-28T05:52:53+00:00Added an answer on May 28, 2026 at 5:52 am

    My solution isn’t elegant and there might be a cleaner solution I’m missing but this is what I did recently. The trick is to keep track of the angle from the last time touchesMoved: is called. Then, add the delta of your current angle and the stored angel value to your total.

    The problem is the “boundaries” that atan2 creates needed ugly code to overcome. Say your lastAngle is 359 and you cross the origin so your next angle is 1. The difference will not be 2 but -358, so whenever you cross that boundary your total will be reset to 0.

    Here is what I did:

     CGFloat angle = atan2f(center.y - point.y, point.x - center.x);
    
     //Translate to Unit circle
     if (angle > 0) {
         angle = (M_PI - angle) + M_PI;
     } else {
         angle = fabsf(angle);
     }
    
     CGFloat delta = angle - lastAngle;
    
     //Adjust for boundaries
     if (fabsf(delta) > (2*M_PI)-fabsf(delta)) {
          BOOL greaterThanZero = (delta > 0);
          delta = (2*M_PI)-fabsf(delta);
          if (greaterThanZero) {
               delta = -1 * delta;
          }
      }
    
      totalAngle += delta;
      lastAngle = angle;
    

    The big/ugly conditional under “Adjust for boundaries” basically just looks to see if there is a shorter angle to get to the new point (So, 2 instead of -258) & assumes that if there is it probably means you crossed that origin and adjusts the delta accordingly.

    I translated the Atan2 results so that it represents a full unit circle from 0 to 2π. Bonus side affect, it then accounts for clockwise/counter clockwise movement better than the standard -π to π of Atan2.

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

Sidebar

Related Questions

I'm working on an app that has lots of UITableViews and I'm trying to
I'm working on a rails app that has a whole bunch of before filters
I'm working on a PHP app that has several objects that can be commented
I am working on a simple app tab-bar based application that has two views.
I am working on an existing ASP.NET MVC app that started small and has
I am working on a C++ app which internally has some controller objects that
I'm working on an app that requires no user input, but I don't want
I'm working on an app that needs to accept a RegEx from the user,
I'm working on an app that has a status menu and from that menu
I am working on an app that has TableViewCells with varying heights. I am

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.