Plum-O-Meter
Plum-O-Meter copied to clipboard
Terezi
var circles = UITouch: CircleWithLabel
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
{
label.hidden = true
for touch in touches
{
let circle = CircleWithLabel()
circle.drawAtPoint(touch.locationInView(view),
force: touch.force / touch.maximumPossibleForce)
circles[touch] = circle
view.layer.addSublayer(circle)
}
highlightHeaviest()
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch in touches where circles[touch] != nil { let circle = circles[touch]!
circle.drawAtPoint(touch.locationInView(view),
force: touch.force / touch.maximumPossibleForce)
}
highlightHeaviest()
}
func highlightHeaviest() { func getMaxTouch() -> UITouch? { return circles.sort({ (a: (UITouch, CircleWithLabel), b: (UITouch, CircleWithLabel)) -> Bool in
return a.0.force > b.0.force
}).first?.0
}
circles.forEach
{
$0.1.isMax = $0.0 == getMaxTouch()
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch in touches where circles[touch] != nil { let circle = circles[touch]!
circles.removeValueForKey(touch)
circle.removeFromSuperlayer()
}
highlightHeaviest()
}