UIDynamics for heatmap

90 Views Asked by At

For a customer I need to realize a UIView which should resemble this one:

To be screen

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:

What I get

The yellow view is the container view passed as referenceView when the animator object is inited (self.pointsReceivedMap)

0

There are 0 best solutions below