use*_*576 88 iphone animation uikit uiview ios
我有一个名为UIView的以下CATransition finalScoreView,它使它从顶部进入屏幕:
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"];
Run Code Online (Sandbox Code Playgroud)
如何使它在它下降后反弹一次然后保持静止?它应该仍然从顶部进入屏幕,但在它关闭时反弹.
任何帮助将不胜感激,谢谢!
huo*_*ong 254
UIDynamicAnimator在iOS 7中更简单的替代方案是Spring Animation(一种新的强大的UIView块动画),它可以通过阻尼和速度为您提供良好的弹跳效果:
Objective C
[UIView animateWithDuration:duration
delay:delay
usingSpringWithDamping:damping
initialSpringVelocity:velocity
options:options animations:^{
//Animations
}
completion:^(BOOL finished) {
//Completion Block
}];
Run Code Online (Sandbox Code Playgroud)
迅速
UIView.animateWithDuration(duration,
delay: delay,
usingSpringWithDamping: damping,
initialSpringVelocity: velocity,
options: options,
animations: {
//Do all animations here
}, completion: {
//Code to run after animating
(value: Bool) in
})
Run Code Online (Sandbox Code Playgroud)
Swift 4.0
UIView.animate(withDuration:duration,
delay: delay,
usingSpringWithDamping: damping,
initialSpringVelocity: velocity,
options: options,
animations: {
//Do all animations here
}, completion: {
//Code to run after animating
(value: Bool) in
})
Run Code Online (Sandbox Code Playgroud)
usingSpringWithDamping 0.0 ==非常有弹性.1.0使其平稳减速而不会过冲.
initialSpringVelocity粗略地说,是"所需距离除以所需的秒数".1.0对应于一秒内遍历的总动画距离.例如,总动画距离为200点,您希望动画的开始与100 pt/s的视图速度匹配,使用值0.5.
在本教程中可以找到更详细的教程和示例应用程序.我希望这对某人有用.
mem*_*ons 142
使用iOS7和UIKit Dynamics,不再需要使用CAKeyframeAnimations或UIView动画!
看看Apple的UIKit Dynamics Catalog应用程序.或者,Teehanlax有一个清晰,简洁的教程,在github中有完整的项目.如果你想要一个关于动力学细节的更详细的教程,Ray Winderlich教程非常棒.与往常一样,Apple文档是一个很好的第一站,因此请查看文档中的UIDynamicAnimator类参考.
以下是Teenhanlax教程的一些代码:
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];
Run Code Online (Sandbox Code Playgroud)
以下是结果

UIKit Dynamics是iOS7中非常强大且易于使用的附加功能,您可以从中获得一些外观漂亮的UI.
其他例子:

实现UIKit动态的步骤始终相同:
UIDynamicAnimator并将其存储在一个强大的属性中UIDynamicBehaviors.每个行为都应该有一个或多个项目,通常是动画视图.UIDynamicBehaviors在UIDynamicAnimator模拟中使用的项目的初始状态是有效状态.| 归档时间: |
|
| 查看次数: |
80441 次 |
| 最近记录: |