为什么我的UIView动画在我把它放在不同类的容器View中时不工作?

问题描述 投票:-1回答:1

我在一个类中做了一个简单的动画。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)
    })
}

这里有一张图片可以更好地解释这个设置: 左边的是... containerView 随着 UIView 和以下是 buttons. 就像我之前说的那样。当所有的东西都在相同的情况下,这工作很好。viewControllerclass. 那为什么现在动画不能用了?我缺少什么?enter image description here

ios swift uiviewcontroller containers uianimation
1个回答
0
投票

有时把动画代码放到主队列中可以解决这个问题。

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

    }
}
© www.soinside.com 2019 - 2024. All rights reserved.