      *   optionally make it animated
      */
     private func showOff(animated: Bool) {
-        thumbView.endTracking(false)
-
-        UIView.animateWithDuration(animationDuration, delay: 0.0, options: [UIViewAnimationOptions.CurveEaseIn, UIViewAnimationOptions.BeginFromCurrentState], animations: {
+        thumbView.endTracking(isOn: false)
+        
+        UIView.animate(withDuration: animated ? animationDuration : 0, delay: 0, options: [.curveEaseIn, .beginFromCurrentState], animations: {
             self.thumbView.frame = self.originalThumbRect
-        }, completion: nil)
+        })
     }
 }

        
        on = false
        
        tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(PMZSwitch.handleTapGesture(_:)))
        tapGestureRecognizer.delegate = self
        self.addGestureRecognizer(tapGestureRecognizer)
    }
    
    // MARK: - Tap gesture recognizer handler -
    
    func handleTapGesture(gestureRecognizer: UITapGestureRecognizer) {
        if ignoreTap {
            return
        }
        
        if gestureRecognizer.state == .Ended {
            thumbView.toggle(true)
            setOn(!on, animated: true)
        }
    }

    // MARK: - UIControl tracking methods -
    
    override public func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool {
        super.beginTrackingWithTouch(touch, withEvent: event)
        
        startTrackingPoint = touch.locationInView(self)
        startThumbFrame = thumbView.frame
        thumbView.startTracking()

        return true
    }
    
    override public func continueTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool {
        super.continueTrackingWithTouch(touch, withEvent: event)
        ignoreTap = true

        // Get touch location
        let lastPoint = touch.locationInView(self)
        let thumbMinPosition = originalThumbRect.origin.x
        let thumbMaxPosition = originalThumbRect.origin.x + maxThumbOffset
        let touchXOffset = lastPoint.x - startTrackingPoint.x
        
        var desiredFrame = CGRectOffset(startThumbFrame, touchXOffset, 0)
        desiredFrame.origin.x = min(max(desiredFrame.origin.x, thumbMinPosition), thumbMaxPosition)
        thumbView.frame = desiredFrame

        if on { // left <- right
            thumbView.animationProgress = (thumbMaxPosition - desiredFrame.origin.x) / maxThumbOffset
        } else { // left -> right
            thumbView.animationProgress = (desiredFrame.origin.x - thumbMinPosition) / maxThumbOffset
        }
        
        return true
    }
    
    override public func endTrackingWithTouch(touch: UITouch?, withEvent event: UIEvent?) {
        super.endTrackingWithTouch(touch, withEvent: event)
        
        if thumbView.center.x > self.bounds.midX {
            setOn(true, animated: true)
        }
        else {
            setOn(false, animated: true)
        }
        
        ignoreTap = false
    }
    
    override public func cancelTrackingWithEvent(event: UIEvent?) {
        super.cancelTrackingWithEvent(event)
        if !ignoreTap {
            return
        }

        // just animate back to the original value
        if on {
            showOn(true)
        } else {
            showOff(true)
        }
        ignoreTap = false
    }
    

     */
    public func setOn(isOn: Bool, animated: Bool) {
        switchValue = isOn
        on ? showOn(animated: animated) : showOff(animated: animated)
    }
    
    /**
     *   Detects whether the switch is on or off
     *
     *     @return    Bool true if switch is on, false otherwise
     */
    public var isOn: Bool {
        return on
    }
    
    // MARK: - Private methods -
    
    /**
     *   Updates the looks of the switch to be in the on position
     *   optionally make it animated
     */
    private func showOn(animated: Bool) {
        thumbView.endTracking(isOn: true)
        
        UIView.animate(withDuration: animated ? animationDuration : 0, delay: 0, options: [.curveEaseIn, .beginFromCurrentState], animations: {
            self.thumbView.frame = self.originalThumbRect.offsetBy(dx: self.maxThumbOffset, dy: 0)
        })
    }
    
    /**
