0

I'm rotating an UIImageView with following code:

CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
[rotate setFromValue:[NSNumber numberWithFloat:0.0]];
[rotate setToValue:[NSNumber numberWithFloat:-0.34906585)]];
[rotate setDuration:0.8];
[rotate setTimingFunction:[CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut]];
rotate.removedOnCompletion = NO;
rotate.fillMode = kCAFillModeForwards;
[myUIImageView.layer addAnimation:rotate forKey:@"dangleMyDial"];

But each time I call this function it start rotating the image from its original position. What should I use for [rotate setFromValue: ]; to make it rotate from where it currently is? is there any property showing the current angle?

(0.34906585 Rad is equal to 20Deg)

4

1 回答 1

1
CATransform3D transform = ((CALayer *) self.myUIImageView.layer.presentationLayer).transform;
CGFloat startAngle = atan2(transform.m12, transform.m11);

CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
[rotate setFromValue:[NSNumber numberWithFloat:startAngle]];
[rotate setByValue:[NSNumber numberWithFloat:-20 * M_PI / 180]];

// ...
于 2013-06-28T00:54:46.157 回答