Skip to content

Commit

Permalink
added delegate methods :
Browse files Browse the repository at this point in the history
    // call before animation
    optional func circleMenu(circleMenu: CircleMenu, buttonWillSelected button: CircleMenuButton, atIndex: Int)

    // call after animation
    optional func circleMenu(circleMenu: CircleMenu, buttonDidSelected button: CircleMenuButton, atIndex: Int)
  • Loading branch information
0ber committed Feb 2, 2016
1 parent 0f04c5f commit 7f2a3f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CircleMenu/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ class ViewController: UIViewController, CircleMenuDelegate {
button.backgroundColor = items[atIndex].color
button.setImage(UIImage(imageLiteral: items[atIndex].icon), forState: .Normal)
}

func circleMenu(circleMenu: CircleMenu, buttonWillSelected button: CircleMenuButton, atIndex: Int) {
print("button will selected: \(atIndex)")
}

func circleMenu(circleMenu: CircleMenu, buttonDidSelected button: CircleMenuButton, atIndex: Int) {
print("button did selected: \(atIndex)")
}
}
10 changes: 10 additions & 0 deletions CircleMenuLib/CircleMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ public func Init<Type>(value: Type, @noescape block: (object: Type) -> Void) ->
// MARK: Protocol

@objc protocol CircleMenuDelegate {

// don't change button.tag
optional func circleMenu(circleMenu: CircleMenu, willDisplay button: CircleMenuButton, atIndex: Int)

// call before animation
optional func circleMenu(circleMenu: CircleMenu, buttonWillSelected button: CircleMenuButton, atIndex: Int)

// call after animation
optional func circleMenu(circleMenu: CircleMenu, buttonDidSelected button: CircleMenuButton, atIndex: Int)
}

// MARK: CircleMenu
Expand Down Expand Up @@ -200,6 +207,8 @@ public class CircleMenu: UIButton {
}

func buttonHandler(sender: CircleMenuButton) {
delegate?.circleMenu?(self, buttonWillSelected: sender, atIndex: sender.tag)

let circle = CircleMenuLoader(
radius: CGFloat(distance),
strokeWidth: bounds.size.height,
Expand All @@ -226,6 +235,7 @@ public class CircleMenu: UIButton {

dispatch_after(dispatchTime, dispatch_get_main_queue(), {
self.customIconView.highlighted = false
self.delegate?.circleMenu?(self, buttonDidSelected: sender, atIndex: sender.tag)
})
}
}
Expand Down

0 comments on commit 7f2a3f8

Please sign in to comment.