[英]How to change rotation point of frame
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?
如何绕框架的右下角旋转?
在开始动画之前添加以下行
self.toNextButton.layer.anchorPoint = // right bottom point on the button
you need to change view.layer's anchorPoints 您需要更改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;
}
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.