Skip to content

Click Event and Listener (Swift)

Weiping Huang edited this page May 13, 2017 · 4 revisions

Listener for clicking each button or animation-states. Check the demo for more details.

Swift | Objective-C

Listener in Each Builder

You can add a simple clicked-closure for each boom-button by adding listeners to each builder of them.

for _ in 0..<bmb.piecePlaceEnum.pieceNumber() {
    let builder = SimpleCircleButtonBuilder.init()
    
    // Event closure when the boom-button corresponding the builder itself is clicked.
    builder.clickedClosure = { (index: Int) -> Void in
        // the boom-button is clicked
    }

    bmb.addBuilder(builder)
}

Listener for BMB

If you want to manager all the click events in one method, you can use BoomDelegate:

...

bmb.boomDelegate = self

...

func boomMenuButton(_ bmb: BoomMenuButton, didClickBoomButtonOfBuilder builder: BoomButtonBuilder, at
index: Int) {
    // If you have implement clickedClosures for boom-buttons in builders,
    // then you shouldn't add any listener here for duplicate callbacks.
    // buttonLabel.text = builder.normalImageName
}

func boomMenuButtonDidClickBackground(boomMenuButton bmb: BoomMenuButton) {
    animationLabel.text = "Click background!!!"
}

func boomMenuButtonWillReboom(boomMenuButton bmb: BoomMenuButton) {
    animationLabel.text = "Will RE-BOOM!!!";
}

func boomMenuButtonDidReboom(boomMenuButton bmb: BoomMenuButton) {
    animationLabel.text = "Did RE-BOOM!!!"
}

func boomMenuButtonWillBoom(boomMenuButton bmb: BoomMenuButton) {
    animationLabel.text = "Will BOOM!!!"
}

func boomMenuButtonDidBoom(boomMenuButton bmb: BoomMenuButton) {
    animationLabel.text = "Did BOOM!!!"
}

State of BMB

Get the states of BMB by:

bmb.isAnimating()  // Whether BMB is animating.
bmb.isBoomed()     // Whether BMB is boomed.
bmb.isReBoomed()   // Whether BMB is re-boomed.

Home
Chapters

  1. Basic Usage
  2. Simple Circle Button
  3. Text Inside Circle Button
  4. Text Outside Circle Button
  5. Ham Button
  6. Share Style
  7. Custom Position
  8. Button Place Alignments
  9. Different Ways to Boom
  10. Ease Animations for Buttons
  11. Different Order for Buttons
  12. Other Animations Attributes for Buttons
  13. Click Event and Listener
  14. Control BMB
  15. Use BMB in Navigation Bar
  16. Use BMB in Table View
  17. Attributes for BMB or Pieces on BMB
  18. Cache Optimization & Boom Area
  19. Change Boom Buttons Dynamically
  20. Blur Background & Tip
  21. Fade Views
  22. Structure of BMB
  23. Version History
Clone this wiki locally