如何在 ios 中获得完美的旋转 UIView 的 X 和 Y 位置

How to get perfect X , Y position of rotating UIView in ios

我正在使用 CABasicanimation 旋转 UIView。我正在使用这段代码,

    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    NSNumber *currentAngle = [CircleView.layer.presentationLayer valueForKeyPath:@"transform.rotation"];
    rotationAnimation.fromValue = currentAngle;
    rotationAnimation.toValue = @(50*M_PI);
    rotationAnimation.duration = 50.0f;             // this might be too fast
    rotationAnimation.repeatCount = HUGE_VALF;     // HUGE_VALF is defined in math.h so import it
    [CircleView.layer addAnimation:rotationAnimation forKey:@"rotationAnimationleft"];

在此我想要在 "UIView" 旋转时完美的 X,Y 位置。 有知道的请帮帮我

提前谢谢你。

那么,如果我没理解错的话,您只是想在旋转过程中获取视图的 X 和 Y 坐标?

您可以通过记录 presentationLayer 的框架来完成此操作,如下所示:

- (IBAction)buttonAction:(UIButton *)sender {

    CGRect position = [[CircleView.layer presentationLayer] frame];
    NSLog(@"%@", NSStringFromCGRect(position));
}

我得到了这个问题的答案,请转到此Link寻找答案