ios - 当我将 UIView 动画放在不同类的 containerView 中时,为什么我的 UIView 动画不起作用?
问题描述
我在 a 上做了一个简单的动画UIView
,它按照我想要的方式工作。但是当我分离代码时它停止工作。我已将UIView
应该动画化的那个放入 acontainerView
并且containerView
连接到animationCode
class
. “主要”也与触发动画的按钮viewController
分开。class
从主要viewController
:
bottomTableView.rx.modelSelected(ModeButtons.self)
.subscribe(onNext: { [weak self] value in
switch value {
case .One:
self?.container.animationOne()
case .Two:
self?.container.animationTwo()
}
}).disposed(by: disposeBag)
和动画功能之一:
func animationOne(){
UIView.animate(withDuration: 0.3, animations: {
self.downarrow?.alpha = 1.0
self.upArrow?.alpha = 1.0
self.leftLine?.frame.size.width = 10.0
self.rightLine?.frame.size.width = 10.0
self.rightLine?.frame.origin.x = self.animationView.frame.width - self.rightLine!.frame.width
self.upArrow?.frame = CGRect(x: self.animationView.frame.width - self.rightLine!.frame.width - self.upArrow!.frame.width - 5.0, y: (self.animationView.frame.height - self.upArrow!.frame.height) / 2, width: self.upArrow!.frame.width, height: self.upArrow!.frame.height)
self.downarrow?.frame = CGRect(x: self.leftLine!.frame.width + 5.0, y: (self.animationView.frame.height - self.upArrow!.frame.height) / 2, width: self.upArrow!.frame.width, height: self.upArrow!.frame.height)
})
}
这是一张可以更好地解释设置的图像:左边是containerView
带有 的UIView
,下面是buttons
. 就像我之前说的。当一切都在同一个viewController
和class
. 那么为什么动画现在不工作了?我错过了什么?
解决方案
有时将动画代码放入主队列可以解决这个问题
DispatchQueue.main.async {
UIView.animate(withDuration: 0.3) {
}
}
推荐阅读
- r - 为什么表达式“1”==1 的计算结果为 TRUE?
- c - 在 serialPutchar() 速度之后切换 Raspberry Pi 上的 GPIO 引脚
- c# - 当 ComboBox ItemsSource 位于 DataGridTemplateColumn 中时,如何在运行时更新它?
- java - FTPSClient 发送二进制文件:“SSLHandshakeException:握手期间远程主机关闭连接”
- delphi - 如何在 Delphi 2007 应用程序中获取已注册接口及其 GUID 的列表?
- doctrine-orm - Doctrine 2 反向 DQL 成员
- eclipse - Eclipse 启动配置为带有图标的单独工具栏按钮
- javascript - Babel 插件 - 使用索引的成员访问
- javascript - 承诺返回 null
- lua - lua 中的 C# 中的“goto”循环是否有等价物?(必须兼容Love2D)