简体   繁体   English

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

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

I am using CABasicanimation for rotate an UIView. 我正在使用CABasicanimation来旋转UIView。 I am using this code, 我正在使用此代码,

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

in this i want perfect X,Y position while "UIView" is rotating. 在这里我想要完美的X,Y位置,而“UIView”正在旋转。 If anyone know please help me. 如果有人知道请帮助我。

Thank you in advance. 先感谢您。 在此输入图像描述

I Got A Answer Of This Question Please Go To This Link For Answer 我得到了这个问题的答案请转到此链接以获得答案

Go to This Link For Answer 转到此链接以获取答案

So, if I understand you correctly, you just want to get the X and Y coordinates of your view during rotation? 所以,如果我理解正确,你只想在旋转过程中获得视图的X和Y坐标?

You can do this by logging the frame of the presentationLayer, like this: 您可以通过记录presentationLayer的框架来完成此操作,如下所示:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM