Francis
Francis

Reputation: 949

UIView does not have member animateWithDuration?

I'm making an iOS8 app and I am trying to animate one of the UIViews. I'm using Swift also. When I try to use the "animateWithDuration" method on my UIView that I created in Interface Builder and then used an IBOutlet to use it in code, Xcode gives me an error,

'UIView' does not have member named 'animateWithDuration'

The only framework I have imported is UIKit. Does anyone now why this isn't working? When I say UIView.animateWithDuration I get no errors, but when I try to use the view I created in Interface Builder I get the error.

Upvotes: 1

Views: 1058

Answers (2)

Vitalii Boiarskyi
Vitalii Boiarskyi

Reputation: 1393

I suppose you a trying to call this method with instance of UIView subclass. But you shouldn't it is class method so use UIView(as Heliem said) and do your changes within its closure.

var myView:MyViewSubclass = MyViewSubclass()

UIView.animateWithDuration(1.0, animations: { () -> Void in
//changes to animate myView
     //to animate frame changes
     myView.Frame = newFrame

})

Upvotes: 1

Zalykr
Zalykr

Reputation: 1524

Perhaps your calling it wrong. It should be:

UIView.animateWithDuration(1.0, animations: { () -> Void in
    //changes to animate
})

That's how class methods are called in swift!

Upvotes: 2

Related Questions