Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terezi #8

Open
seyfullaalizada opened this issue Jan 5, 2021 · 0 comments
Open

Terezi #8

seyfullaalizada opened this issue Jan 5, 2021 · 0 comments

Comments

@seyfullaalizada
Copy link

seyfullaalizada commented Jan 5, 2021

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, 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, withEvent event: UIEvent?)
{
for touch in touches where circles[touch] != nil
{
let circle = circles[touch]!

        circles.removeValueForKey(touch)
        circle.removeFromSuperlayer()
    }
    
    highlightHeaviest()

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant