Thanks to @Szu for pointing me out to UIKit Dynamics :)
Here's a rough solution:
Call init with a controller's view (to be bounced) and a reference view (your current view controller's view property).
eg.
FSBounceAnimator(contentView: viewController.view, referenceView: self.view)
viewController is any viewController that you may instantiated and added as a childViewController
self.view is your current viewController view.
Call bounce(), to bounce :)
import UIKit
class FSBounceAnimator: NSObject {
var animator: UIDynamicAnimator
var gravityBehaviour: UIGravityBehavior
var pushBehavior: UIPushBehavior
var itemBehaviour: UIDynamicItemBehavior
init(contentView: UIView!, referenceView: UIView!) {
animator = UIDynamicAnimator(referenceView: referenceView)
var colisionBehaviour: UICollisionBehavior = UICollisionBehavior(items: [contentView])
colisionBehaviour.setTranslatesReferenceBoundsIntoBoundaryWithInsets(UIEdgeInsetsMake(-100, 0, 0, 0))
animator.addBehavior(colisionBehaviour)
gravityBehaviour = UIGravityBehavior(items: [contentView])
gravityBehaviour.gravityDirection = CGVectorMake(1, 1)
animator.addBehavior(gravityBehaviour)
pushBehavior = UIPushBehavior(items: [contentView], mode: UIPushBehaviorMode.Instantaneous)
pushBehavior.magnitude = 0.0
pushBehavior.angle = 0.0
animator.addBehavior(pushBehavior)
itemBehaviour = UIDynamicItemBehavior(items: [contentView])
itemBehaviour.elasticity = 0.45
animator.addBehavior(itemBehaviour)
super.init()
}
func bounce() {
self.pushBehavior.pushDirection = CGVectorMake(0.0, 100.0);
self.pushBehavior.active = true;
}
}