Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: could not find an overload for ' ' that accepts the supplied arguments

So what I need is an image to rotate continuously. The problem is at /// UIView.animateWithDuration() (0.01, animations: { ///

where it says: Could not find an overload for 'animateWithDuration' that accepts the supplied arguments

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let schedule = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: Selector("rotate"), userInfo: nil, repeats: true)
    schedule.fire()

    func rotate() {
        angle = angle + 1

        UIView.animateWithDuration() (0.01, animations: { 
            self.imageView.transform = CGAffineTransformMakeRotation( ((self.angle) / 180.0 * M_PI));
            })
    }
}

@IBOutlet var imageView : UIImageView

var angle = 0

Thanks in advance.

like image 831
perte Avatar asked Jan 25 '26 09:01

perte


1 Answers

As @Bryan Chen pointed out, you have an extra () in the method call. But, that's not your only problem. Your angle variable is an Int, when it's expected to be a Double which causes this error. Change your variable declaration to be a Double

var angle = 0.0

And use doubles throughout, like when modifying the variable.

angle = angle + 1.0

And then this will work without error.

UIView.animateWithDuration(0.01, animations: {
    self.imageView.transform = CGAffineTransformMakeRotation( ((self.angle) / 180.0 * M_PI));
})
like image 192
Mick MacCallum Avatar answered Jan 28 '26 03:01

Mick MacCallum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!