Reset timer when the app resigned
This commit is contained in:
parent
050e495744
commit
ed34ebf37b
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "GMStepper"
|
||||
s.version = "1.0.0"
|
||||
s.version = "1.0.1"
|
||||
s.summary = "A stepper with a sliding label in the middle."
|
||||
s.homepage = "https://github.com/gmertk/GMStepper"
|
||||
s.screenshots = "https://dl.dropboxusercontent.com/u/4397140/pod-screenshots/screenshot_1.png"
|
||||
|
|
|
|||
|
|
@ -264,6 +264,8 @@ import UIKit
|
|||
backgroundColor = buttonsBackgroundColor
|
||||
layer.cornerRadius = cornerRadius
|
||||
clipsToBounds = true
|
||||
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: "reset", name: UIApplicationWillResignActiveNotification, object: nil)
|
||||
}
|
||||
|
||||
public override func layoutSubviews() {
|
||||
|
|
@ -286,15 +288,20 @@ import UIKit
|
|||
value -= stepValue
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
resetTimer()
|
||||
NSNotificationCenter.defaultCenter().removeObserver(self)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Pan Gesture
|
||||
extension GMStepper {
|
||||
func handlePan(gesture: UIPanGestureRecognizer) {
|
||||
leftButton.enabled = false
|
||||
rightButton.enabled = false
|
||||
|
||||
switch gesture.state {
|
||||
case .Began:
|
||||
leftButton.enabled = false
|
||||
rightButton.enabled = false
|
||||
case .Changed:
|
||||
var translation = gesture.translationInView(label)
|
||||
gesture.setTranslation(CGPointZero, inView: label)
|
||||
|
|
@ -333,8 +340,7 @@ extension GMStepper {
|
|||
self.rightButton.backgroundColor = self.buttonsBackgroundColor
|
||||
self.leftButton.backgroundColor = self.buttonsBackgroundColor
|
||||
}
|
||||
|
||||
case .Ended:
|
||||
case .Ended, .Cancelled, .Failed:
|
||||
reset()
|
||||
default:
|
||||
break
|
||||
|
|
@ -345,8 +351,10 @@ extension GMStepper {
|
|||
panState = .Stable
|
||||
stepperState = .Stable
|
||||
resetTimer()
|
||||
|
||||
leftButton.enabled = true
|
||||
rightButton.enabled = true
|
||||
label.userInteractionEnabled = true
|
||||
|
||||
UIView.animateWithDuration(self.labelSlideDuration, animations: {
|
||||
self.label.center = self.labelOriginalCenter
|
||||
|
|
@ -387,7 +395,6 @@ extension GMStepper {
|
|||
|
||||
func buttonTouchUp(button: UIButton) {
|
||||
reset()
|
||||
label.userInteractionEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue