April 2015
Intermediate to advanced
556 pages
17h 47m
English
Your users have been clamoring for a way to roll the die. The designer thinks that double-clicking on it would be a sensible way to accomplish this, so let’s add it. Add a randomize() method to DieView:
func randomize() {
intValue = Int(arc4random_uniform(5)) + 1
}
In mouseUp(_:), use NSEvent’s clickCount to check for the double-click before calling randomize():
override func mouseUp(theEvent: NSEvent) {
println("mouseUp clickCount: \(theEvent.clickCount)")
if theEvent.clickCount == 2 {
randomize()
}
}
That was easy. Run the application and roll the die by clicking on it. It is not bad, but it would be much more satisfying if the die visually reacted to the mouse down. Specifically, you will shift the die shape ...
Read now
Unlock full access