【问题标题】:How to get perfect X , Y position of rotating UIView in ios如何在ios中获得旋转UIView的完美X、Y位置
【发布时间】:2016-01-13 10:09:57
【问题描述】:

我正在使用 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"];

在这个我想要完美的 X、Y 位置,而“UIView”正在旋转。 如果有人知道,请帮助我。

提前谢谢你。

【问题讨论】:

  • 您能否再解释一下您所说的完美 x 和 y 位置是什么意思以及您的视图必须以哪种方式旋转?您是否希望它在 Z 轴上旋转(所以在 3D 空间中?)。
  • 实际上,我在两侧旋转我的 UIView 并在点击事件中旋转,当这个 UIView 旋转时,我想要一个 UIView 的完美位置,它实际上在哪个位置。
  • 我想要一个 (X,Y) 的位置
  • 不 它不像 3d 不在 z 中。我只是在 UIView 的同一位置上旋转 UIVew。

标签: ios rotation position cabasicanimation


【解决方案1】:

我得到了这个问题的答案,请转到此链接以获得答案

Go to This Link For Answer

【讨论】:

    【解决方案2】:

    所以,如果我理解正确的话,您只是想在旋转过程中获取视图的 X 和 Y 坐标?

    您可以通过记录presentationLayer的框架来做到这一点,如下所示:

    - (IBAction)buttonAction:(UIButton *)sender {
    
        CGRect position = [[CircleView.layer presentationLayer] frame];
        NSLog(@"%@", NSStringFromCGRect(position));
    }
    

    【讨论】:

    • 你好朋友,谢谢你的回答,但这不是给我一个完美的位置
    • 我试过你的代码和我的答案,你是对的,presentationlayer 没有在 superviews 坐标空间中给出正确的坐标。此刻,我不明白为什么。如果我知道了,我会回来的。
    • 好的,谢谢,如果您对此有任何想法,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-02
    相关资源
    最近更新 更多