【问题标题】:Why doesn't my UIView animation work when I put it in a containerView in a different class?当我将 UIView 动画放在不同类的 containerView 中时,为什么我的 UIView 动画不起作用?
【发布时间】:2020-05-08 05:29:34
【问题描述】:

我在UIView 上做了一个简单的动画,它按我想要的方式工作。但是当我分离代码时它停止工作。我已将应该动画的UIView 放入containerView 中,并且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)
    })
}

下面的图片可以更好地解释设置:左边是containerViewUIView,下面是buttons。就像我之前说的。当一切都在同一个viewControllerclass 中时,这工作得很好。那么为什么动画现在不工作了?我错过了什么?

【问题讨论】:

  • animationOne 这个函数被调用了?
  • 是的,它贯穿了整个事情,但没有动画显示......
  • 请发布更多代码....或检查网点..您的图像在容器中还是按钮在?
  • 在每一行之前,打印目标。例如,在self.downarrow?.alpha = 1.0 之前,放置print(self.downarrow)。对每一行都这样做。运行应用程序并制作动画。打印什么?

标签: ios swift uiviewcontroller containers uianimation


【解决方案1】:

有时将动画代码放入主队列可以解决这个问题

DispatchQueue.main.async {
    UIView.animate(withDuration: 0.3) {

    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多