动画视图缩放弹跳?
有没有一种方法可以对视图进行动画处理,使其放大并有点走得太远,然后用橡皮筋恢复到最终尺寸?我不确定如何制作这种动画。
Is there a way to animate a view so that it zooms up and kinda goes a bit too far and rubberbands back to the final size? I'm unsure how to do this sort of animation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
如今,这可以通过更简单的方式完成:
This can be done in a much simpler way these days:
阿米特的回答很好并且被接受了。我在这里为那些想要在 Swift/future 中开发的人发布该答案的 Swift 版本。我使用 Xcode 7.3.1 和 Swift 2.2 来开发它。
谢谢,请评论更新。
更新
这是 Swift 3 的相同代码。适用于 Xcode 8 和 iOS 10。
希望这有帮助。
Amit's answer is nice and accepted one. I am posting the Swift version of that answer over here for someone who wants to develop in Swift/future. I have used Xcode 7.3.1 and Swift 2.2 to develop this.
Thanks and please do comment for update.
UPDATE
Here is the same code for Swift 3. Works well with Xcode 8 and iOS 10.
Hope this helped.
只是为了将来的代码重用和保持代码干净。
Just for future code reuse and keeping code clean.
使用以下代码来实现缩放弹跳动画。
Use following code for zoom bouncing animation.
与 iOS9 和 xCode 7 一起使用
Used with iOS9 and xCode 7
检查 Xcode 中 UIView 类参考中的动画相关部分。提示:使用变换属性。
Check the animation related section in UIView Class Reference in your Xcode. Hint: use transform property.
Swift 5
完成时回调。
使用:
Swift 5
With a callback on completion.
Use:
当您想触发此动画时编写此代码
SWIFT 5.0
这是更新的代码(来自 fabio.cionini),因为它已被接受答案,因此更新到最新版本。
write this code when you want to trigger this animation
SWIFT 5.0
This is updated code (from fabio.cionini) as it is accepted answer so updating to latest.
Amit Singh 刚刚使用块重构了代码,这使得代码更加简单和可读。
Just refactored the code by Amit Singh using blocks, which makes it much simpler and readable.
太多复杂的答案
Too many complicated answers ????. It's much easier to do it as of 2017 (Swift 3/4).
Swift 4-
Note the
usingSpringWithDamping
parameter. This parameter dictates how much bounce/spring effect you want and allows values from 0 to 1. The lower the value the more the bounce effect. Also, if you do not like thescaleBy
effect then you can simply use good old frames to show a expanding and bouncingUIView
.