0

我正在尝试通过旋转为我的框架设置动画:

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

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

[UIView commitAnimations];

但是这段代码围绕他的中心旋转框架。如何围绕框架的右下角进行旋转?

4

2 回答 2

2

在开始动画之前添加以下行

self.toNextButton.layer.anchorPoint = // right bottom point on the button
于 2012-10-05T06:53:23.773 回答
2

你需要改变 view.layer 的 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;
}

你应该像这样实现。

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

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

[UIView commitAnimations];
于 2012-10-05T06:53:27.573 回答