This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BallView: UIImageView { | |
init(size: CGFloat) { | |
super.init(frame: CGRect(origin: .zero, size: CGSize(width: size, height: size))) | |
image = UIImage(named: "basketball-png-0") | |
contentMode = .scaleToFill | |
layer.cornerRadius = size * 0.5 | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let pushBehaviour = UIPushBehavior(items: [mainModalView], mode: .instantaneous) | |
pushBehaviour.pushDirection = velocity.vector * Constants.pushForceRatio | |
pushBehaviour.setTargetOffsetFromCenter(offset, for: mainModalView) | |
animator.addBehavior(pushBehaviour) | |
animator.addBehavior(gravityBehaviour) | |
animator.removeBehaviors(itemsAttachmentBehaviours) | |
// Handy extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modalViewExitBehaviour = UIDynamicItemBehavior(items: [targetView]) | |
// Action is called in every animation step | |
modalViewExitBehaviour.action = { [unowned self] _ in | |
// Check if all views are outside of the reference frame | |
if !self.allViews.contains(where: { $0.frame.intersects(self.superview.bounds) }) { | |
self.onDismiss?() | |
} | |
} | |
animator?.addBehavior(modalViewExitBehaviour) | |
OlderNewer