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

  • SEARCH
  • Home
  • 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 8263487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:07:16+00:00 2026-06-08T04:07:16+00:00

I have used following code and I can rotate my image. But after animation

  • 0

I have used following code and I can rotate my image. But after animation I don’t know how to get the final angle of an image.

I want to calculate Rotation angle of an image after “touch ended” event.

- (void)rotateAccordingToAngle:(float)angle
{
    [NumbersImage setTransform:CGAffineTransformRotate(NumbersImage.transform, angle)];  
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{    
    [NumbersImage.layer removeAllAnimations];
    previousTimestamp = event.timestamp;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    if ([touch view] == NumbersImage) {

    CGPoint center = CGPointMake(CGRectGetMidX([NumbersImage bounds]), CGRectGetMidY([NumbersImage bounds]));
    CGPoint currentTouchPoint = [touch locationInView:NumbersImage];
    CGPoint previousTouchPoint = [touch previousLocationInView:NumbersImage];
    CGFloat angleInRadians = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);

    [self rotateAccordingToAngle:angleInRadians];

    CGFloat angleInDegree = RadiansToDegrees(angleInRadians);
    FinalDegree +=angleInDegree;        
    revolutions+= (angleInDegree/360.0f);
}

}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];

if ([touch view] == NumbersImage) {

    NSTimeInterval timeSincePrevious = event.timestamp - previousTimestamp;
    CGFloat revolutionsPerSecond = revolutions/timeSincePrevious;

    [self startAnimationWithRevolutions:revolutionsPerSecond forTime:5.0f];
    NSLog(@"Revolution per second = %f",revolutionsPerSecond);

    revolutions = 0;
}
}

CGFloat RadiansToDegrees(CGFloat radians)
{
    //NSLog(@"Radians %f",radians);
    return radians * 180 / M_PI;
};


- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
NumbersImage.userInteractionEnabled = TRUE;
    if (timerUpdate) {
        [timerUpdate invalidate];
        timerUpdate = nil;
    }
}
-(void)updateTransform{
    NumbersImage.transform = [[NumbersImage.layer presentationLayer] affineTransform];
}
-(void)startAnimationWithRevolutions:(float)revPerSecond forTime:(float)time
{
    NumbersImage.userInteractionEnabled = FALSE;
    float totalRevolutions = revPerSecond * time;

    timerUpdate = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(updateTransform) userInfo:nil repeats:YES];

    [CATransaction begin];
    [CATransaction setValue:[NSNumber numberWithFloat:time]forKey:kCATransactionAnimationDuration];

    CABasicAnimation* spinAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
CGAffineTransform transform = NumbersImage.transform;

float fromAngle = atan2(transform.b, transform.a);
float toAngle = fromAngle + (totalRevolutions*4*M_PI);

NSLog(@"To Angle = %f",toAngle);
NSLog(@"From Angle = %f",fromAngle);
spinAnimation.fromValue = [NSNumber numberWithFloat:fromAngle];
spinAnimation.toValue = [NSNumber numberWithFloat:toAngle];
spinAnimation.repeatCount = 0;
spinAnimation.removedOnCompletion = NO;
spinAnimation.delegate = self;
spinAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[NumbersImage.layer addAnimation:spinAnimation forKey:@"spinAnimation"];
[CATransaction commit];


//NSLog(@"Total Rotation = %f",totalRevolutions);

//NSLog(@"Degree Rotation %f", temp);

//[self Rotate];
CGFloat temp = RadiansToDegrees(fromAngle);
FinalDegree += temp;
//NSLog(@"FinalDegree %f",FinalDegree);


//NSLog(@"Final degree %f",FinalDegree);
//NSLog(@"Total %f",total);

}

CGFloat DegreesToRadians(CGFloat degrees)
{
    return degrees * M_PI / 180;
}

This code is used to measure velocity and rotate image as per user touch.

But I am not able to get the final angle of the image.

Please somebody help me in this code.

Thanks,

Hemang.

  • 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-08T04:07:18+00:00Added an answer on June 8, 2026 at 4:07 am

    You have done the wrong approach. Take a look here:

    1. Declare an instance float x; and make it zero in viewDidLoad.
    2. In touchesMoved increment your x by 1 (or decrement, depending on which direction you have detected).
    3. Keep in mind: x is your angle in degrees, so if decrementing leads under zero, do x = 360.0;, and vice versa: if incrementing leads above 360.0, do x = 0.0;
    4. Also there in touchesMoved say:

    myImageView.transform = CGAffineTransformMakeRotation(x * M_PI/180);

    By the way, you will always know the angle – it’s x.

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

Sidebar

Related Questions

I have never used Foxpro before. Can you convert the following Foxpro code into
I have used the following code to pick up an image from phone's gallery:
I have used the following code to get the document root. $path = get_file_dir();
I have the following code. It's used to combine various image attachments (and pdfs)
I have used the following code to convert the image in a PictureBox into
I have used the following code to connect between java and mysql, but it
I have used the following code to display the previous and after years of
I have used the following code to make a table but in the tag
I have used following code to convert string to json and parse it. String
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as

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.