In my app I have two sort buttons that looks like a custom segmented control.
The VC inits with Button1 selected. If you then press on Button2 a UIView will animate from Button1 to Button2 - this is effect to show what button is selected
My code looks like this:
@IBAction func BtnOneDidTouch(sender: AnyObject) {
myLabel.text = "Button 1"
UIView.animateWithDuration(0.7,
delay: 0,
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0.5,
options: nil,
animations: {
self.underLine.center = CGPointMake(self.btnOne.center.x, self.btnOne.center.y + 16)
}, completion: nil
)
}
@IBAction func BtnTwoDidTouch(sender: AnyObject) {
myLabel.text = "Button 2"
UIView.animateWithDuration(0.7,
delay: 0,
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0.5,
options: nil,
animations: {
self.underLine.center = CGPointMake(self.btnTwo.center.x, self.btnTwo.center.y + 16)
}, completion: nil
)
}
underLine is the view that is being animated.
If I comment out
myLabel.text = "Button 1"
and myLabel.text = "Button 2"
from the functions it will work. But If I leave them, it does not work.
It fails by: If you click on Btn2 the view will slide then jump back again and only the text label will be changed.
What I want to is to have the view slide and stay and change the label as well.