Magnetic icon indicating copy to clipboard operation
Magnetic copied to clipboard

Restart animation on viewWillAppear

Open lumo2707 opened this issue 6 years ago • 2 comments

Hi, is it possible to restart animation so that when the user comes back on the screen the bubbles will be animated from besides to center?

lumo2707 avatar Jan 02 '19 09:01 lumo2707

I can add a function to restart the animation. However in the meanwhile you can add this extension to adjust the node position.

extension Magnetic {
    func restartAnimation() {
        for (index, node) in children.enumerated() {
            let x = (index % 2 == 0) ? -node.frame.width : frame.width + node.frame.width
            let y = CGFloat.random(node.frame.height, frame.height - node.frame.height)
            node.position = CGPoint(x: x, y: y)
        }
    }
}

efremidze avatar Jan 03 '19 14:01 efremidze

@efremidze just FYI where i use it is upon device rotation when my container resizes - it seems out of the box this is not handled by Magnetic.

az-oolloow avatar Jul 07 '19 15:07 az-oolloow