Self Scrollable text inside CAScrollLayer

前端 未结 1 765
慢半拍i
慢半拍i 2020-12-07 06:20

I want to have text inside of a CAScrollLayer scroll by itself from starting point to ending point and then reset the animation. However I cannot seem to get a CATextLayer i

相关标签:
1条回答
  • 2020-12-07 06:41

    One hardly needs or wants a CAScrollLayer or a CATextLayer for this. Simply start with a superview that clips to its bounds, and inside that put a UILabel. Animate the sideways movement of the label and you're done.

    Here's a rough sketch:

        let w1 = self.lab.frame.width
        let w2 = self.lab.superview!.frame.width
        let w = w1 - w2
        let x = self.lab.frame.origin.x
        UIView.animateWithDuration(5, delay: 0, options: .CurveLinear, animations: {
            self.lab.frame.origin.x -= w
            }, completion: {
                _ in
                self.lab.frame.origin.x = x
        })
    

    enter image description here

    0 讨论(0)
提交回复
热议问题