1

I have a button (openMenu) that I am animating down (works fine) and rotate (works the first time) with a "drawer". The first time it rotates it works.. but when I try to rotate again it wigs out and hides the image and shows the button title? Any ideas of why? I need it to just rotate back another 45 degrees. Don't know why it would do this.

Also - see GIF image below so you see what is happening.

- (void)viewDidLoad
{

    [super viewDidLoad];

    draw1 = 0;
    scrollView.frame = CGRectMake(0, -200, 768, 200);
    [scrollView setContentSize:CGSizeMake(768, 200)];
    openMenu.frame = CGRectMake(680, 100, 55, 55);

}




- (IBAction)openMenu:(id)sender {

    if (draw1 == 0) {

        draw1 = 1;

        CGRect optionsDrawer = scrollView.frame;
        CGRect optionsButton = openMenu.frame;
        optionsDrawer.origin.y += 200;
        optionsButton.origin.y += 200;
        [UIView animateWithDuration:0.5
                         animations:^{
                             scrollView.frame = optionsDrawer;
                             openMenu.frame = optionsButton;
                             openMenu.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(45));
                         }];
    } else {

        draw1 = 0;

        CGRect optionsDrawer = scrollView.frame;
        CGRect optionsButton = openMenu.frame;
        optionsDrawer.origin.y -= 200;
        optionsButton.origin.y -= 200;
        [UIView animateWithDuration:0.5
                         animations:^{
                             scrollView.frame = optionsDrawer;
                             openMenu.frame = optionsButton;
                             openMenu.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(45));
                         }];
    }

}

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Sean Herman
  • 313
  • 2
  • 15
  • If I change openMenu.transform = CGAffineTransformMakeRotation(M_PI / 2); for the first one and openMenu.transform = CGAffineTransformMakeRotation(-M_PI / 2); it works! BUT! That is rotating is 180 degrees. When I do -M_PI / 4, it has the same issue as above. I don't know why this just isn't working with 45 degrees rotations?! – Sean Herman Sep 04 '13 at 17:55
  • Shouldn't you rotate it back to 0 degrees? – morksinaanab Feb 04 '14 at 18:21

2 Answers2

3

Do like this, i am using layers to animate, it is easy, once u rotate, dont need to rotate again, just brings back to original state. I did like this it works for me, just try this. since i am using layers add "QuartzCore" library and import this


 #import<QuartzCore/QuartzCore.h> //include this

 if (draw1 == 0) 
 { 
    ....//your code
    [UIView animateWithDuration:0.1 animations:^{
     detailButton.layer.transform = CATransform3DMakeRotation((180) * 45, 0, 0, 1);
 }];

 } 
 else
 {

 ....//your code

   [UIView animateWithDuration:0.1 animations:^{
    detailButton.transform = CGAffineTransformIdentity; //brings back to original position by animating
}];


}


hope this helps u :)

Shankar BS
  • 8,394
  • 6
  • 41
  • 53
0

If you want to rotate the button back - you need to provide negative number as the value for CGAffineTransformMakeRotation().

Here is the snippet from Apple Docs:

CGAffineTransformMakeRotation()

Returns an affine transformation matrix constructed from a rotation value you provide.

CGAffineTransform CGAffineTransformMakeRotation ( CGFloat angle );

The angle, in radians, by which this matrix rotates the coordinate system axes. In iOS, a positive value specifies counterclockwise rotation and a negative value specifies clockwise rotation. In OS X, a positive value specifies clockwise rotation and a negative value specifies counterclockwise rotation.

Hope this helps!

Community
  • 1
  • 1
  • I've tried doing this in the above code. I am already converting to radians. – Sean Herman Sep 04 '13 at 17:48
  • If I do openMenu.transform = CGAffineTransformMakeRotation(M_PI / 2); to rotate and openMenu.transform = CGAffineTransformMakeRotation(-M_PI / 2); to "reverse it" it works. But that is 180 degrees... i need 45 degrees. If i do M_PI / 4 it doesn't work at all? – Sean Herman Sep 04 '13 at 17:49