如何创建一个UIView反弹动画? [英] How to create a UIView bounce animation?

查看:163
本文介绍了如何创建一个UIView反弹动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为的UIView finalScoreView 以下CATransition,这使得它从顶部进入屏幕:

I have the following CATransition for a UIView called finalScoreView, which makes it enter the screen from the top:

CATransition *animation = [CATransition animation];
animation.duration = 0.2;
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromBottom;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

[gameOver.layer addAnimation:animation forKey:@"changeTextTransition"];
[finalScoreView.layer addAnimation:animation forKey:@"changeTextTransition"];

我如何使它所以它涉及下来后,再撑还是它反弹一次?它仍然应该从顶部进入屏幕,但随后反弹,当它归结。

How do I make it so it bounces once after it comes down, then stays still? It should still enter the screen from the top but then bounce when it comes down.

任何帮助将是非常美联社preciated,谢谢!

Any help would be much appreciated, thanks!

推荐答案

随着iOS7和UIKit动力,就没有必要再使用 CAKeyframeAnimations 的UIView 动画!

With iOS7 and UIKit Dynamics, there is no longer any need to use CAKeyframeAnimations or UIView animations!

看看<一个href=\"https://developer.apple.com/library/ios/sample$c$c/DynamicsCatalog/Introduction/Intro.html\">Apple's UIKit的动态目录应用。或者, Teehanlax已与的 =HTTPS:/在GitHub上 /github.com/TeehanLax/UIKit-Dynamics-Example\">full项目。如果您想了解动态的插件和奏更详细的教程中,雷Winderlich教程是大。与往常一样,苹果文档是一个伟大的第一站,所以检查出的<一个href=\"https://developer.apple.com/library/ios/documentation/uikit/reference/UIDynamicAnimator_Class/Reference/Reference.html\">UIDynamicAnimator在文档类引用。

Take a look at Apple's UIKit Dynamics Catalog app. Alternately, Teehanlax has a clear, concise tutorial with the full project in github. If you want a more detailed tutorial about the ins-and-outs of dynamics, the Ray Winderlich tutorial is great. As always, the Apple docs are a great first stop, so check out the UIDynamicAnimator Class reference in the docs.

下面是一个有点从Teenhanlax教程中的code的:

Here's a bit of the code from the Teenhanlax tutorial:

self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];

UIGravityBehavior* gravityBehavior = 
                [[UIGravityBehavior alloc] initWithItems:@[self.redSquare]];
[self.animator addBehavior:gravityBehavior];

UICollisionBehavior* collisionBehavior = 
                [[UICollisionBehavior alloc] initWithItems:@[self.redSquare]]; 
collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;
[self.animator addBehavior:collisionBehavior];

UIDynamicItemBehavior *elasticityBehavior = 
                [[UIDynamicItemBehavior alloc] initWithItems:@[self.redSquare]];
elasticityBehavior.elasticity = 0.7f;
[self.animator addBehavior:elasticityBehavior];

和这里的结果。

的UIKit Dynamics是一个真正强大且易于使用的除iOS7,你可以从它那里得到一些非常好看的UI。

UIKit Dynamics is a really powerful and easy to use addition to iOS7 and you can get some great looking UI from it.

其他的例子:




实施动态的UIKit的步骤总是相同的:

The steps to implement UIKit dynamics is always the same:


  1. 创建一个 UIDynamicAnimator 并将其存储在一个强大的属性

  2. 创建一个或多个 UIDynamicBehaviors 。每种行为应该有一个或多个项目,通常的图进行动画。

  3. 确保在使用的项目的初始状态 UIDynamicBehaviors UIDynamicAnimator 模拟中的有效状态

  1. Create a UIDynamicAnimator and store it in a strong property
  2. Create one or more UIDynamicBehaviors. Each behavior should have one or more items, typically a view to animate.
  3. Make sure that the initial state of the items used in the UIDynamicBehaviors is a valid state within the UIDynamicAnimator simulation.

这篇关于如何创建一个UIView反弹动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆