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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:30:33+00:00 2026-06-03T15:30:33+00:00

I have a custom UIView. It initializes two rectangular UIBezierPaths, and in drawRect it

  • 0

I have a custom UIView. It initializes two rectangular UIBezierPaths, and in drawRect it simply fills these two paths.

This view is placed on a button. When the button is clicked, a rotation is applied to it inside an animateWithDuration block:

icon.transform = CGAffineTransformMakeRotation(M_PI*-0.25);

This works great.

When the button is clicked again, I am trying to make the view rotate back to it’s original orientation (reverse the rotation). I have tried:

icon.transform = CGAffineTransformInvert(icon.transform);
icon.transform = CGAffineTransformMakeRotation(M_PI*0.25);
icon.transform = CGAffineTransformIdentity;

… and a number of other variations, but none of them seem to work. Instead, the view is distorted until it’s no longer visible — sorta stretched to nothing. Sometimes, reapplying the first transform brings it back but with other reversals it doesn’t.

What am I doing wrong?

  • 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-03T15:30:34+00:00Added an answer on June 3, 2026 at 3:30 pm

    In ios the transform is always relative, so once transformation is done, the next transformation should be relative to the previous transformation. You can simply change the frame of the view and revert it back to normal on second button click. On even clicks you will have to revert back the frame. Implement the following code. You can use the block level code if you feel comfortable with it as it is the new norm.

    int noOfClicks = 0;
    
    -(IBAction)yourBtnAction:(id)sender
    {
        noOfClicks++;
    
        if(noOfClicks %2 != 0)
        {
            [UIView beginAnimations:@"Rotate" context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationDelegate:self];
            CGRect frame=yourView.frame;
            frame.origin.y+=20;
            yourview.frame=frame;
            [UIView commitAnimations];
        }
        else
        {
            [UIView beginAnimations:@"Rotate" context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationDelegate:self];
            CGRect frame=yourView.frame;
            frame.origin.y-=20;
            yourview.frame=frame;
            [UIView commitAnimations];
        }
    }
    

    If you don’t want to make so many change you can use following to revert back but employing same logic:

    [UIView beginAnimations:@"Rotate back" context:nil];
    [UIView setAnimationDuration:1.0];
    
    yourView.transform = CGAffineTransformIdentity;
    
    [UIView commitAnimations];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a custom UIView which is presented from a UIViewController . This view
I have a simple custom UIView (a rectangle) that is implemented with drawRect. The
I have a custom UIView class. Inside that view, there is an image view.
I have a custom subclass of UIView, LineDrawingView. I have this as a @property
I have a custom UIView, which I have placed using Xcode (4). I need
I have a custom UIView class, and in the - (void)drawRect:(CGRect)rect I want to
I have a custom UIView subclass without a corresponding UIViewController. I use this class
I have created a UIView subclass in order to implement a custom drawRect method.
I have created a table view and i am adding my custom uiview into
i have a custom UIView class,and i have linked my view in IB with

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.