hoshy hoshy - 2 months ago 15
Swift Question

UIView.animateWithDuration on UITextfield's contentoffset: It clips the text (Swift)

I use the following code:

UIView.animateWithDuration(30, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: {
self.textView.contentOffset = CGPointMake(0, 700)
}, completion: nil)


If the contentOffset is up to about 100, the animation works correctly and all text is visible. Everything higher than that leads to the disappearance of text at the beginning of the textlabel during the animation. The higher the contentOffset, the more text disappears during the animation. So I see white space for a while and then the remaining text comes into animation. Also: Once the animation is done, all text is visible again when I scroll up.

I have tried multiple UITextviews in various superviews. The general idea is a kind of Credits like animation where all text moves slowly upwards for about 30 seconds.

Answer

You can try looping small animations together like the following.

func animate(count:Int)
{
    if (count > 100)
    {
        return
    }
    UIView.animateWithDuration(1, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: {

        self.textView.contentOffset = CGPointMake(0, self.textView.contentOffset.y + 10)
        }, completion: { finished in
            dispatch_async(dispatch_get_main_queue(),{
                self.animate(count+1)
        })
    })

}
Comments