Armin Armin - 1 year ago 108
Swift Question

Swift - static member animate cannot be used on instance of type uiview

I'm using the pod EasyAnimate and I'm trying to do something very simple but I get this error:


static member animate cannot be used on instance of type uiview


I'm using this code inside a closure that detects when an API request is completed. And that is inside the viewDidLoad function, which is inside my ViewController. I have removed irrelevant code to make it easy to read.

import UIKit
import Alamofire
import EasyAnimation

class WeatherVC: UIViewController, UITableViewDelegate, UITableViewDataSource {

//Launchscreen Outlets
@IBOutlet weak var launchScreenImage: UIImageView!
@IBOutlet weak var launchScreenLbl: UILabel!
@IBOutlet weak var launchScreenBG: UIView!


override func viewDidLoad() {
super.viewDidLoad()

currentWeather = CurrentWeather()
currentWeather.downloadWeatherDetails {
self.downloadForecastData {
self.updateMainUI()

// Start animation from launch screen
launchScreenBG.animate(duration: 2.0, animations: { <<<ERROR HERE
self.view.layer.position.x = 200.0
})
}

}

}


}


I thought this .animate function works on all UIViews, but I'm not sure what the issue is. It doesn't seem to care that it's inside a closure, and it doesn't seem to matter if I add
self.
before the UILabel name.

I can see that this pod allows animations for classes. But how do I animate an
IBOutlet
?

Any ideas what's going on here? Thanks so much in advance.

Answer Source

A static method can only be called on the class it is implemented on:

UIView.animate(duration: 2.0, animations: { 
   //Do something with launchScreenBG here. For example:
   self.launchScreenBG.alpha = 0.0
})

This method essentially animates all view updates (transparency in this case) that are provided in the block.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download