在单个Uiview.transition块中为Uilabel和Uibutton动画吗?
我需要动画化Uilabel和Uibutton的图像属性的变化。
我目前使用两个Uiview.Transition块,这些块似乎正常,但是看起来很糟糕,而且我肯定是避免重复代码的更好的方法。目前这样做:
UIView.transition(with: label, duration: 1, options: [.curveEaseInOut, .transitionCrossDissolve], animations: {
self.label.text = someText
}, completion: nil)
UIView.transition(with: aButton, duration: 1, options: [.curveEaseInOut, .transitionCrossDissolve], animations: {
self.aButton.setImage(aUIImage, for: .normal)
}, completion: nil)
afaik没有init for uiview.transition,它会吸收一系列的Uiviews来动画或类似的东西。
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
概念
似乎没有“内置”方法可以在一个
uiview.transition
动画块中过渡多个视图。相反,如果我们有一种控制过渡而没有块,我们可以尝试自己制作。输入
catransition
!您可以使用
catransition
将交叉分解效果添加到calayer
类似:答案
catransition
可以同时添加到多层。因此,我们可以使用这些知识来编写自己的代码,该代码将这种过渡应用于多层(或视图)。我继续为您制作了
uiview
扩展。剥离版本看起来像这样:您可以传递要过渡的视图列表,并在一个块中执行所有过渡更改。
讨论
我添加了更多功能(例如动画曲线,延迟等),并制作了更可用的版本,并在此处发布了它。
当然,这种方法有缺点。您将失去所有基于“翻转”过渡的花式过渡。这是因为CoreAimation Transition API只有一些基本的(但不错的)效果。
随意订购存储库并为您的喜好进行调整。
Concept
Looks like there are no 'built-in' ways to transition multiple views within one
UIView.transition
animation block.Instead, we can try to make our own if we had a way to control transitions without blocks. Enter
CATransition
!You can use
CATransition
to add cross-dissolve effects toCALayer
like so:Answer
CATransition
objects can be added to multiple layers at the same time. So we can use this knowledge to write our own code that applies this transition to multiple layers (or views) at the same time.I went ahead and made a
UIView
extension for you. The stripped down version looks like this:You can pass the list of views you want to transition and perform all the transition changes in a single block.
Discussion
I added some more functionality (like animation curve, delay, etc.) and made a more usable version of this and posted it here.
Of course there are disadvantages with this approach. You lose all the fancy transitions built in such as the "flip" transition. This is because the CoreAnimation Transition API only has some basic (but nice) effects baked in.
Feel free to fork the repo and tweak it for your liking.