ios - swift ActivityIndi​​cator 自动停止动画

标签 ios swift animation tableview uiactivityindicatorview

我有一个带有多个 tableviewcell 的 tableview。每个单元格都有一个 UIActivityIndi​​catorView,它根据状态触发:

private func stateDidChange(duration: NSTimeInterval) {
    switch self.state {
    case .Failed:
       self.testingIndicator.stopAnimating()
        self.animateWithColor(self.redColor.CGColor)
        break
    case .Success:
        self.testingIndicator.stopAnimating()
        self.animateWithColor(self.greenColor.CGColor)
        break
    case .Testing:
        self.testingIndicator.startAnimating()
        self.animateWithColor(self.greyColor.CGColor)
        break
    case .Unknown:
        self.testingIndicator.stopAnimating()
        self.animateWithColor(self.greyColor.CGColor)
        break
    }
}
private func animateWithColor(color: CGColor) {
    CATransaction.begin()
    CATransaction.setAnimationDuration(self.duration)
    CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut))
    self.shapeLayer.strokeColor = color
    CATransaction.commit()
}

第二个函数对指示器周围的圆圈的描边颜色进行动画处理。 我正在使用这个观察者来观察状态变化:

 var state: TestStepModel.State {
        didSet {
                self.stateDidChange(self.duration)
        }
 }

到目前为止,一切都按预期进行,但如果只有一个单元格发生变化,我会更新每个单元格。 所以我将这段代码添加到观察者中:

 var state: TestStepModel.State {
        didSet {
            if state != oldValue {
                self.stateDidChange(self.duration)
            }
        }
 }

突然间,一旦第一个状态发生变化,每个单元格中的每个事件指示器都会停止动画。 更糟糕的是,我可以像这样取消每个 .stopAnimating() 调用的注释:

switch self.state {
    case .Failed:
        //self.testingIndicator.stopAnimating()
        self.animateWithColor(self.redColor.CGColor)
        break
    case .Success:
        //self.testingIndicator.stopAnimating()
        self.animateWithColor(self.greenColor.CGColor)
        break
    case .Testing:
        self.testingIndicator.startAnimating()
        self.animateWithColor(self.greyColor.CGColor)
        break
    case .Unknown:
        //self.testingIndicator.stopAnimating()
        self.animateWithColor(self.greyColor.CGColor)
        break
    }

并且在第一个状态更改后它仍然停止动画。是的,除了这三个(在整个项目中搜索)之外,没有其他 stopAnimating() 调用。

所以,是的,这当然是一个非常奇怪和具体的问题,但也许有人知道如何解决它或面临类似的问题...... 事件指示器应该仅在我调用 .stopAnimating() 时停止并隐藏,但当我触发状态更改时它会停止。

最佳答案

我遇到了同样的问题,我所做的就是停止重新加载 Collection View 。让我知道这是否有帮助,否则我也可以分享代码片段。

关于ios - swift ActivityIndi​​cator 自动停止动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38291356/

相关文章:

CSS动画。来自[显示无;宽度 : 0] to [display inline; width: auto]

ios - 在 TableView 上检测滑动手势

ios - ios 上的网络音频与音频队列冲突,仅在设备上

ios - 如何发送变量和照片以在 Apple Watch 上显示

ios - 找不到目标 'MyCustomFramework' 的模块 'x86_64-apple-ios-simulator' ;找到 : arm64, armv7-apple-ios,arm64-apple-ios,arm,armv7

c# - 在 XNA 中创建二维多边形

Javascript 动画打开/关闭菜单

ios - 当射弹击中两个 "monsters"时,didBeginContact 方法崩溃。我知道为什么,但我不知道如何避免

swift - 为什么 'nil' 与 Swift 3 中的 'UnsafePointer<CGAffineTransform>' 不兼容?

ios - 如何仅在 Swift 中的特定对象上覆盖函数?