9

I am using CABasicanimation for rotate an 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. How can I achieve this?

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Hardik Vyas
  • 1,973
  • 1
  • 20
  • 43
  • Can you please explain a little bit more what you mean by perfect x and y position and which way your view has to rotate? Do you want it to rotate in the Z axis (so in 3D space?). – Tuslareb Jan 13 '16 at 10:20
  • Actually i am rotating my UIView in both side and on click event and when this UIView is rotating i want a perfect position of that UIView that at which position it is actually. – Hardik Vyas Jan 13 '16 at 10:22
  • i want a position in manner of (X,Y) – Hardik Vyas Jan 13 '16 at 10:23
  • No It is not like 3d not in z. i am simply rotating UIVew on same position of UIView. – Hardik Vyas Jan 13 '16 at 10:27

1 Answers1

0

So, if I understand you correctly, you just want to get the X and Y coordinates of your view during rotation?

You can do this by logging the frame of the presentationLayer, like this:

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

    CGRect position = [[CircleView.layer presentationLayer] frame];
    NSLog(@"%@", NSStringFromCGRect(position));
}
Tuslareb
  • 1,200
  • 14
  • 21
  • Hello Friend Thanx For Your Answer But This not give me a perfect position – Hardik Vyas Jan 13 '16 at 10:57
  • 1
    I tried your code and my answer, you are right, the presentationlayer doesn't give the correct coordinates in the superviews coordinate space. At this moment, I do not understand why. I'll come back to it if I find out. – Tuslareb Jan 13 '16 at 11:49
  • Ok Thanx Please Tell me if you are having any idea about it. – Hardik Vyas Jan 13 '16 at 11:54