Reputation: 263
I am using the following function to move self.view to the specified x axis:
func shiftMainContainer(#targetPosition: CGFloat, completion: ((Bool) -> Void)! = nil) {
UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.5, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
self.view.frame.origin.x = 300
println("View should shift")
}, completion: completion)
}
When I call this function from an @IBAction button in the same view, it works, but when I call it using a delegate method from a sub-view, nothing happens. I know that the delegate works because the println prints the text like it should, but the view isn't shifted like in the first scenario.
Does calling it from a subview delegate make a difference?
Can anyone point me in the right direction? I've been banging my head on the wall for this for the better part of the day now.
Manage to reproduce the problem in a new blank project. Check it out here:
https://github.com/EugeneTeh/DelegateAnimateTest
Upvotes: 0
Views: 272
Reputation: 493
In my case it works fine for me when I added self.view.layoutIfNeeded()
func shiftMainContainer(#targetPosition: CGFloat, completion: ((Bool) -> Void)! = nil) {
UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.5, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
self.view.frame.origin.x = 300
println("View should shift")
self.view.layoutIfNeeded()
}, completion: completion)
}
Upvotes: 0