samedi 12 août 2017

If then statement in swift?

My problem is I am trying to figure out a way to code a sort of 'if then' statement, and add it to my code. I am trying to get it so when whiteDot is dragged and the if (whiteDot.frame.contains(smallDot.frame) && smallDot.image != nil) statement is executed then the whiteDot must be dragged back to the center and center.frame.contains(whiteDot.frame) must be executed before the if (whiteDot.frame.contains(smallDot.frame) && smallDot.image != nil) statement can be executed again. So it would sort of look like this, if (whiteDot.frame.contains(smallDot.frame) && smallDot.image != nil) { score += 1 } then after above statement executed (center.frame.contains(whiteDot.frame)) must be executed

 @IBAction func handlePan(recognizer:UIPanGestureRecognizer) {
    let translation = recognizer.translation(in: self.view)
    if let view = recognizer.view {
        view.center = CGPoint(x:view.center.x + translation.x,
                              y:view.center.y + translation.y)
    }
    recognizer.setTranslation(CGPoint.zero, in: self.view)

@IBOutlet weak var smallDot: UIImageView!

@IBOutlet weak var center: UIImageView!

@IBOutlet weak var whiteDot: UIImageView!


    if (whiteDot.frame.contains(smallDot.frame) && smallDot.image != nil)
{ score += 1  }

enter image description here

Aucun commentaire:

Enregistrer un commentaire