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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:30:30+00:00 2026-05-20T23:30:30+00:00

I want to rotate the below image on a center point using one finger

  • 0

I want to rotate the below image on a center point using one finger touch…

And i want to display the value of the image with the label when I rotate the image using touch.

I have done the image rotation but the problem is that how to set the value of the image according to rotation.

The angle of the rotation is increase so i can not set the value.

Can any one help me?

The code is below

float fromAngle = atan2(firstLoc.y-imageView.center.y, 
                            firstLoc.x-imageView.center.x);

    NSLog(@"From angle:%f",fromAngle);
    float toAngle = atan2( currentLoc.y-imageView.center.y, 
                          currentLoc.x-imageView.center.x);

    NSLog(@"to Angle:%f",toAngle);
    // So the angle to rotate to is relative to our current angle and the
    // angle through which our finger moved (to-from)
    float newAngle =angle+(toAngle-fromAngle);


    NSLog(@"new angle:%.2f",newAngle);


 CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle);

 imageView.transform=cgaRotate;


angle = newAngle;

Can any one help me ?

  • 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-20T23:30:31+00:00Added an answer on May 20, 2026 at 11:30 pm

    Wasn’t totally sure what you were after; but try out this code.

    If you create a new View-based Application project called ‘Rotation’ and replace the code in RotationViewController.h and .m for the following you’ll get a green block that you can rotate using your calculations. You can replace the green block UIView with your UIImageView, or anything else you want to spin.


    RotationViewController.h

    #import <UIKit/UIKit.h>
    
    @interface RotationViewController : UIViewController
    {
        UIView* m_block;
        UILabel* m_label;
        CGPoint m_locationBegan;
        float m_currentAngle;
    }
    
    - (float) updateRotation:(CGPoint)_location;
    
    @end
    

    RotationViewController.m

    #import "RotationViewController.h"
    
    double wrapd(double _val, double _min, double _max)
    {
        if(_val < _min) return _max - (_min - _val);
        if(_val > _max) return _min - (_max - _val);
        return _val;
    }
    
    @implementation RotationViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        CGRect blockFrame = CGRectMake(0, 0, 200, 200);
        m_block = [[UIView alloc] initWithFrame:blockFrame];
        m_block.backgroundColor = [UIColor greenColor];
        m_block.center = self.view.center;
        [self.view addSubview:m_block];
        [m_block release];
        
        CGRect labelFrame = CGRectMake(0, 0, 320, 30);
        m_label = [[UILabel alloc] initWithFrame:labelFrame];
        m_label.text = @"Loaded";
        [self.view addSubview:m_label];
    }
    
    - (void) touchesBegan:(NSSet *)_touches withEvent:(UIEvent *)_event
    {
        UITouch* touch = [_touches anyObject];
        CGPoint location = [touch locationInView:self.view];
        m_locationBegan = location;
    }
    
    - (void) touchesMoved:(NSSet *)_touches withEvent:(UIEvent *)_event
    {
        UITouch* touch = [_touches anyObject];
        CGPoint location = [touch locationInView:self.view];
        [self updateRotation:location];
    }
    
    - (void) touchesEnded:(NSSet *)_touches withEvent:(UIEvent *)_event
    {
        UITouch* touch = [_touches anyObject];
        CGPoint location = [touch locationInView:self.view];
        m_currentAngle = [self updateRotation:location];
    }
    
    - (float) updateRotation:(CGPoint)_location
    {
        float fromAngle = atan2(m_locationBegan.y-m_block.center.y, m_locationBegan.x-m_block.center.x);
        float toAngle = atan2(_location.y-m_block.center.y, _location.x-m_block.center.x);
        float newAngle = wrapd(m_currentAngle + (toAngle - fromAngle), 0, 2*3.14);
    
        CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle);
        m_block.transform = cgaRotate;
        
        int oneInFifty = (newAngle*50)/(2*3.14);
        
        m_label.text = [NSString stringWithFormat:@"Angle: %f 1in50: %i", newAngle, oneInFifty];
    
        return newAngle;
    }
    
    @end
    

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

Sidebar

Related Questions

I want to rotate a image with UIslider control. I have done that with
I want to rotate the image around its center point.The problem i am facing
I have an image shown below: I want to rotate this handle when user
I have an object which I first want to rotate (about its own center)
Please following the below image: I want to transform a Rectangle with anchor point
I'm trying to rotate an image around the center. This works generally using RotateAnimation,
I have a <span> that I want to rotate. I am using HTML5, CSS3,
Hi I want to rotate a control on its right bottom point(like a clock
I have a cube which I want to rotate. I also have a light
We want to scale, rotate and drag functionality in flash as3. I do have

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.