shu223 / Pulsator

Pulse animation for iOS
MIT License
1.42k stars 160 forks source link

Dismiss Pulsator and CGPoint position not working. #16

Closed HackShitUp closed 3 years ago

HackShitUp commented 7 years ago

There's two things that I can't seem to get working or can't figure out. First, the .position protocol doesn't recognize the CGPoint value and is always set to the upper left corner of the screen. Next, how do I dismiss the pulsator after starting it?

andrewjedi commented 7 years ago

Same issue for me too

HackShitUp commented 7 years ago

@andrewfashion have you figured it out yet???

AdrianBinDC commented 7 years ago

Here's how I got it working...

1) Declare a Pulsator on MyViewController:

let pulsator = Pulsator()

2) In viewDidLoad, set your pulsator properties what view you want to add it to, etc.

yourImageView.layer.superlayer?.insertSublayer(pulsator, below: yourImageView.layer)
pulsator.numPulse = 3
pulsator.backgroundColor = UIColor.red.cgColor
pulsator.radius = containerView.bounds.width / 2

This is why mine wasn't centering in the imageView 3) If you don't have viewDidLayoutSubviews configured, do so...

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    view.layer.layoutIfNeeded()
    pulsator.position = yourImageView.center
}

4) Wherever you want it to start pulsing, then call pulsator.start(). Wherever you want it to stop, call pulsator.stop()