0

I'm trying to animate my frame with rotation:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];

self.toNextButton.transform = CGAffineTransformMakeRotation(180.0f);

[UIView commitAnimations];

But this code rotate frame around his center. How can I make rotation around right bottom corner of frame?

RomanHouse
  • 2,552
  • 3
  • 23
  • 44
  • you can try to set the center point of the `toNextButton` in xib to it's right bottom corner may this will solve your problem :) – The iOSDev Oct 05 '12 at 06:49
  • 1
    Check this post: http://stackoverflow.com/questions/6160519/how-to-rotate-an-object-around-a-arbitrary-point – Bijoy Thangaraj Oct 05 '12 at 06:52

2 Answers2

2

Add the following lines before you start animation

self.toNextButton.layer.anchorPoint = // right bottom point on the button
S.P.
  • 3,054
  • 1
  • 19
  • 17
2

you need to change view.layer's anchorPoints

-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view
{

    CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y);
    CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y);

    newPoint = CGPointApplyAffineTransform(newPoint, view.transform);
    oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform);

    CGPoint position = view.layer.position;

    position.x -= oldPoint.x;
    position.x += newPoint.x;

    position.y -= oldPoint.y;
    position.y += newPoint.y;

    view.layer.position = position;
    view.layer.anchorPoint = anchorPoint;
}

and you should implement like this.

[self setAnchorPoint:CGPointMake(1,1)];
UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];

self.toNextButton.transform = CGAffineTransformMakeRotation(180.0f);

[UIView commitAnimations];
David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
Romit M.
  • 898
  • 11
  • 28