擅长:python、mysql、java
<p>使用ios pythonista场景实现此动画</p>
<pre><code>import scene
label_text = 'abcdefghijklmnopqrstuvwxyz'
def custom_action(node, progress):
ntext = node.text
i = int(len(ntext)*progress)
iminus1txt = ntext[i-1].lower() if i > 0 else ''
ithtxt = ntext[i].capitalize() if i < len(ntext) else ''
if i > 0:
before_i = ntext[:(i-1)]
else:
before_i = ''
if i < len(ntext):
node.text = before_i+iminus1txt+ithtxt+ntext[(i+1):]
else:
node.text = label_text
class TextCapitalAnimate(scene.Scene):
def setup(self):
center = self.bounds.center()
labelnode = scene.LabelNode(label_text, font=('Courier', 20),
position=center, parent=self)
A = scene.Action
animate_action = A.repeat(A.call(custom_action, 2), 0)
labelnode.run_action(animate_action)
scene.run(TextCapitalAnimate())
</code></pre>