BWCircularSlider
BWCircularSlider copied to clipboard
NaN error when touch point is the same as the centre of the circle.
If the user's drag coordinate is at the centre of the CircularSlider, a crash occurs because of a "divide by zero" issue.
in function moveHandle() :
func moveHandle(lastPoint:CGPoint){
//Get the center
let centerPoint:CGPoint = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
//Calculate the direction from a center point and a arbitrary position.
//bug fix:
var currentAngle:Double = AngleFromNorth(centerPoint, p2: lastPoint, flipped: false);
if currentAngle.isNaN {
currentAngle = 0
}
let angleInt = Int(floor(currentAngle))
//Store the new angle
angle = Int(360 - angleInt)
//Update the textfield
textField!.text = "\(angle)"
//Redraw
setNeedsDisplay()
}