4
votes

I have had an animation that I have recently caught to be not working

//time is a variable used in my code
UIView.animate(withDuration: time, delay: 0, options: [.curveLinear, .allowUserInteraction], animations: {

                //this class is ofType UIScrollView
                self.setContentOffset(CGPoint(x: self.contentSize.width-self.frame.width, y: 0), animated: false)

            //Completion Handler
            }, completion: { finished in

                    //It's always true, not sure a way to fix this
                    if(finished ) {

But, later in my code, I have a method to remove certain animations, specifically from this scrollView.

self.layer.removeAllAnimations()

It gets called, and I would assume it is suppose to make the above

if(finished ) { //Here

return false, therefore it should not go inside the finished. But, finished is ALWAYS true. Whether I cancel this animation, continue the animation, doesn't matter what I do to the animation, the completion handler is always true. Any tips on this matter?

1

1 Answers

2
votes

Your call to setContentOffset specifies animated:false, if that is the only property you are changing, then there are no actual animations going on, so the call to .animate(...) will always complete with a value of true. If you set this property (or another one) with animated:true and your duration is too short for the animation to finish, then it could complete with a false value for the parameter.