【问题标题】:UIImageView rotation animation with easy outUIImageView 旋转动画很容易出
【发布时间】:2012-06-29 01:45:45
【问题描述】:

我现在正在旋转一个圆形箭头。这很酷,但我希望在结束时像其他视图一样有一些更精致的东西,你可以动画它们来缓解进出,我想知道您是否可以为此做同样的事情..这是我的代码..

- (IBAction)animator:(id)sender
{
    [arrowRotation removeFromSuperview];

    //arrow animation
    arrowRotation = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];
    arrowRotation.frame = CGRectMake(148.0, 20.0, 30.0, 30.0);
    [self.view addSubview:arrowRotation];



    CABasicAnimation *fullRotation;
    fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    fullRotation.fromValue = [NSNumber numberWithFloat:0];
    fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
    fullRotation.duration = 0.75f;
    fullRotation.repeatCount = 3;

    [arrowRotation.layer addAnimation:fullRotation forKey:@"360"];
}

所以我的问题是,当涉及到 3 次旋转时,我可以让这个动画放慢速度吗?就像 UIView 的轻松。如果这有意义..

任何帮助将不胜感激。

【问题讨论】:

    标签: iphone ios uiimageview cabasicanimation


    【解决方案1】:

    首先,在fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)]; 这一行中,您的浮点数((360*M_PI)/180) 会将圆圈旋转360 度,但您的数字有点过大。我的意思是您可以将其简化为2*M_PI

    第二:如果你想更多地自定义这个,你可以使用CAKeyframeAnimation

    CAKeyframeAnimation *rotationAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
    
    NSArray *rotationValues = [NSArray arrayWithObjects: [NSNumber numberWithFloat: 0], [NSNumber numberWithFloat: (2*M_PI)], nil];
    
    [rotationAnimation setValues:rotationValues];
    
    NSArray *rotationTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],[NSNumber numberWithFloat:1.0f], nil];
    [rotationAnimation setKeyTimes:rotationTimes];
    
    NSArray *rotationTimingFunctions = [NSArray arrayWithObjects:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut],  nil];
    [rotationAnimation setTimingFunctions:rotationTimingFunctions];
    
    rotationAnimation.fillMode = kCAFillModeForwards;
    rotationAnimation.removedOnCompletion = NO;
    rotationAnimation.duration = 1;
    
    [self.view.layer addAnimation:rotationAnimation forKey:@"animation"];
    

    希望这会有所帮助!

    【讨论】:

    • 很酷,感谢您帮助我更好地理解事物.. 我仍然认为它无法实现我正在寻找的简单方法,但没关系.. 我仍在尝试学习动画的东西.. 我有只做过对 UIViews 等的基本调用。现在我有一些时间,我想了解一些很酷的东西,但只是想确保我做的事情是正确的。谢谢你的帮助。
    • @HurkNburkS 如果您对代码有任何其他问题或不明白的地方,请随时提问。
    • 帅哥,谢谢大家.. 只是现在阅读 ios 库中的一些函数.. 我应该很可爱.. 但如果我这样做了,我会让你知道 :)
    【解决方案2】:

    使用UIView animateWithDuration:delay:options:animations:completion: 制作动画并使用选项UIViewAnimationOptionCurveEaseOut。这是 iOS 上更新后的首选 UIView 动画方法,可让您轻松完成所需的操作。

    这里的文档:http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

    如果您有任何问题,请告诉我!

    【讨论】:

    • 好建议。虽然 UIView 的 animateWithDuration:delay:options:animations:completion: 方法是 UIView 动画的首选动画方法,但 不是整体首选的动画方法。最好的动画方法是 Core Animation 和 OpenGL 框架中的方法,因为它们是硬件加速的,允许更复杂的动画而不用担心性能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多