shu223 / Pulsator

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

Can't get the pulse positioned behind a button... #36

Closed designfrontier closed 3 years ago

designfrontier commented 7 years ago

Also setting pulsator.position makes it disappear completely?

       pulsator.position = self.view.center
        pulsator.numPulse = 5
        pulsator.radius = 70
        pulsator.repeatCount = .greatestFiniteMagnitude
        pulsator.animationDuration = 3
        pulsator.backgroundColor = UIColor(red: 0, green: 0.755, blue: 0.756, alpha: 1).cgColor
        button.layer.insertSublayer(pulsator, below: button.layer)
        pulsator.start()
designfrontier commented 7 years ago

with the position line commented out it appears slightly above and to the right of the button

abhishekb21 commented 6 years ago

Facing similar issue

marko-mni commented 6 years ago

Hi, try changing this line: button.layer.insertSublayer(pulsator, below: button.layer) with: "buttons PARENT VIEW".layer.insertSublayer(pulsator, below: button.layer) This works for me hope it helps :).

vishnu-cz commented 6 years ago

@designfrontier Hey this must be happening because you are setting it before subview layout properly. You need to paste this code in viewDidLayoutSubviews function , it should work fine

rami965 commented 3 years ago

Try putting it in viewDidAppear

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    guard button.layer.sublayers?.contains(pulsator) != true else { return } // prevent adding the layer multiple times
    button.layer.insertSublayer(pulsator, at: .zero)
}