A.Pinhasov A.Pinhasov - 7 months ago 14
Swift Question

UIview dose not respond at calling view controller

the weirds thing is happing to me, i have a uiviewcontroller and inside it a UIView with 2 Views to display an illusion of a graph bar as:

The UIVIEW with bars

now the thing is the first time i open the view controller nothing happens ,the bars don't raise, after switching to another view and then coming back Everything works great and bars raises.
now here is the catch, ViewDidLoad and ViewWillApper use the Same Functions and by break points and println all the data reachs the uiviewAnimation for the rise of the bars, yet nothings happens,unless reloading the view

What is going on? please inlight me

override func viewDidLoad() {
super.viewDidLoad()


TimeNow()

InsertNetoToCircul()
InsertSpendIntoCircul()
Checking()
AdvicesFunction()


}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)

InsertNetoToCircul()
InsertSpendIntoCircul()
Checking()
AdvicesFunction()


}


func SpendBar(high : CGFloat,income:Float){

if high < 1{
OtzaotLabel.hidden = true
}
else{
OtzaotLabel.hidden = false
}
if income < 1{
LoLabel.hidden = true
}
else{
LoLabel.hidden = false
}


SpendBarView.frame.origin.x = 38
SpendBarView.frame.origin.y = 335

SpendBarView.frame.size.width = 70

// Calculate location in bar
//Spendings
var Mana:Int = (Int(high) / 500) * 30
var Sher:Float! = ((Float(high) % 500) / 500 ) * 30

if Rate{ Mana /= 2 }


UIView.animateWithDuration(0.4, animations: {

self.SpendBarView.frame.size.height = -CGFloat(Float(Mana) + Sher)

})

SpendBarView.backgroundColor = UIColor(red: 1.0, green: 0.4, blue: 0.4, alpha: 1)}

Answer

You can't do an animation in viewDidLoad because the view is not in the interface yet. The view is loaded; that means that the view controller has a view. But the is not yet added to the interface. You cannot perform an animation on a view before it is added the interface; you can't even perform an animation on a view in the same runloop as when you add it to the interface. The view must already be in the interface, and fully established there, before you attempt to animate it.