For a customer I need to realize a UIView which should resemble this one:
My idea was to use UIDynamics and some sort of UIFieldBehaviour. So I created a container view containerView, added a bunch of UIViews. Those internal views are added to a UIFieldBehavior.magneticField() (using addItem).
I also create a UICollisionBehaviour adding the same UIViews
Here below the code:
let _animator = UIDynamicAnimator.init(referenceView: self.pointsReceivedMap)
let _magnet = UIFieldBehavior.magneticField()
let _collisions = UICollisionBehaviour()
_collisions.translatesReferenceBoundsIntoBoundary = true
for index in 1..<10 {
let view = UIView();
/*add some UI style to view */
_collision.addItem(view)
_magnet.addItem(view)
}
_animator.addBehaviour(_magnet)
_animator.addBehaviour(_collision)
And this is what I get:
The yellow view is the container view passed as referenceView when the animator object is inited (self.pointsReceivedMap)