added delegate methods :

// 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)
This commit is contained in:
Alex.k
2016-02-02 12:25:49 +03:00
parent 0f04c5fea2
commit 7f2a3f8a89
2 changed files with 18 additions and 0 deletions
+8
View File
@@ -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
View File
@@ -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
@@ -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,
@@ -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)
})
}
}