【问题标题】:Animate view - Spin, shrink and move off screen动画视图 - 旋转、缩小和移出屏幕
【发布时间】:2012-06-06 14:50:06
【问题描述】:

我有一个自定义 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

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

谢谢

【问题讨论】:

    标签: ios xcode uianimation


    【解决方案1】:

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

    【讨论】:

    • 对不起,我想我在编辑我的问题的同时你一定已经回答了。我现在轮换工作正常,我只需要休息。
    • 我会使用更复杂的动画类之一,它允许您为动画设置多个值。
    • 你会如何处理更复杂的类?阅读这个问题stackoverflow.com/questions/518530/… 建议我使用的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多