0

我有一个自定义 UIView 类,我想同时以随机角度旋转、收缩和移出屏幕。

我有这段代码可以旋转层几次

- (void)spinLayer:(CALayer *)inLayer duration:(CFTimeInterval)inDuration currentAngle:(CGFloat)curAngle
        direction:(int)direction
{
    CABasicAnimation* rotationAnimation;

    // Rotate about the z axis
    rotationAnimation = 
    [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    // Rotate 360 degress, in direction specified
    rotationAnimation.toValue = [NSNumber numberWithFloat:(M_PI * 4 * direction) + curAngle];

    // Perform the rotation over this many seconds
    rotationAnimation.duration = inDuration;

    // Set the pacing of the animation
    rotationAnimation.timingFunction = 
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

    // Add animation to the layer and make it so
    [inLayer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

我这样称呼:

CGFloat angle = atan2(sender.transform.b, sender.transform.a);  // Current angle
[self spinLayer:sender.layer duration:0.5 currentAngle:angle direction:1]; //direction can be -1

但是我现在如何缩小视图并同时移动它呢?

谢谢

4

1 回答 1

1

将视图旋转 360 度不会产生动画,因为开始和结束状态是相同的。您应该尝试使用多个值作为旋转值。

于 2012-06-06T15:02:57.313 回答