jeudi 23 juillet 2020

How can I click a button multiple times and repeat the function?

I am new to app development and am starting by writing a 'Wheel of fortune' app in Xcode. I have a button and a wheel, and when I first launch the app I can click the button and the wheel will spin, however if I click the button again nothing happens and I have to restart the app, to click the button and make it spin. I have enclosed the code that I've used. I would appreciate if anyone take a look over my code and help me :)

The image of my code.

Here's my code in case you can't open the image.

import UIKit

import AudioToolbox

import AVFoundation

var count = 1

class ViewController: UIViewController {
    
    @IBOutlet weak var Wheel: UIImageView!
    @IBOutlet weak var Label: UILabel!
    
    @IBAction func rotateButton(_ sender: Any) {

        playSound (sound: "spinSound", type: "mp3")
        
        var usedNumbers = [Int]()

        let rotateButton = Int.random(in: 1...20)
        Label.text = String(rotateButton)

        if usedNumbers.contains (rotateButton) {

        } else {

        usedNumbers.append(rotateButton)

        }
        
        UIView.animate(withDuration: Double(rotateButton)) { () -> Void in
          self.Wheel.transform = CGAffineTransform(rotationAngle: CGFloat(rotateButton))
        }

            UIView.animate(withDuration: Double(rotateButton), delay: Double(rotateButton)/2, options: UIView.AnimationOptions.curveEaseIn, animations:  { () -> Void in
            self.Wheel.transform = CGAffineTransform(rotationAngle: CGFloat(rotateButton))
        }, completion: nil)
            }
}



Aucun commentaire:

Enregistrer un commentaire