Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds delegate protocol and notification #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions SevenSwitch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,23 @@
import UIKit
import QuartzCore

@objc protocol SevenSwitchDelegate {

/*
* Notifies the delegate, that switch animation has completed.
*/
func didFinishAnimating()
}

@IBDesignable @objc public class SevenSwitch: UIControl {

// public

/*
* Delegate object, that is going to be notified when switch animation is completed.
*/
var delegate: AnyObject?

/*
* Set (without animation) whether the switch is on or off
*/
Expand Down Expand Up @@ -442,6 +455,7 @@ import QuartzCore
self.offLabel.alpha = 0
}, completion: { finished in
self.isAnimating = false
self.notifyDelegate()
})
}
else {
Expand Down Expand Up @@ -493,6 +507,7 @@ import QuartzCore

}, completion: { finished in
self.isAnimating = false
self.notifyDelegate()
})
}
else {
Expand All @@ -515,5 +530,15 @@ import QuartzCore
currentVisualValue = false
}

func notifyDelegate() {
let selector: Selector = "didFinishAnimating"
if delegate != nil {
if delegate!.respondsToSelector(selector) {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
delegate!.performSelector(selector)
})
}
}
}

}