Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何更改帧的旋转点_Iphone_Objective C_Ios_Ipad - Fatal编程技术网

Iphone 如何更改帧的旋转点

Iphone 如何更改帧的旋转点,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,我正在尝试使用旋转设置帧的动画: [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; self.toNextButton.transform = CGAffineTransformMakeRotation(180.0f); [UIView commitAnimations]; 但这个代

我正在尝试使用旋转设置帧的动画:

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

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

[UIView commitAnimations];

但这个代码是围绕他的中心旋转的。如何围绕帧的右下角旋转?

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

self.toNextButton.layer.anchorPoint = // right bottom point on the button

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

self.toNextButton.layer.anchorPoint = // right bottom point on the button

您需要更改视图。图层的锚点

-(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];

您需要更改视图。图层的锚点

-(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];

您可以尝试将xib中的
toNextButton
的中心点设置到它的右下角,这可能会解决您的问题:)检查此帖子:您可以尝试将xib中的
toNextButton
的中心点设置到它的右下角,这可能会解决您的问题:)检查此帖子:
anchorPoint
它必须是按钮的右下角?在这种情况下,我的按钮正在消失。
anchorPoint
它必须位于按钮的右下角?在这种情况下,我的按钮不见了。。