ios - 滚动 uitableviewcell 后 UIView.animateWithDuration 停止

标签 ios swift uitableview tableview uianimation

我在 uiTableViewCell 中添加了一个无限动画,它只是在表格 View 单元格内闪烁一个 UILabel。

我的问题是,当我滚动 tableview 时它只是停止闪烁

我的代码是

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("TripListCell", forIndexPath: indexPath) as! TripListCell
    
    let trip = tripList[indexPath.section]
    cell.lblTripDirection.textColor = UIColor(red: 51/255, green: 210/255, blue: 123/255, alpha: 1.0)
    
    UIView.animateWithDuration(0.5, delay: 0.0, options: [.CurveEaseInOut, .Repeat, .Autoreverse, .AllowUserInteraction], animations: {
        
        cell.lblTripDirection.alpha = 0.0
        }, completion: {
            bool in
        cell.lblTripDirection.alpha = 1.0
        cell.lblTripDirection.textColor = UIColor.blackColor()
    })
    return cell
}

更新:

UIView.commitAnimations() 在返回对我有用的单元格之前。 谢谢大家:)

最佳答案

这是因为 cellForRowAtIndexPath 重新使用同一个单元格来显示其他数据。所以你不应该在 cellForRowAtIndexPath 中编写你的动画。

你应该尝试在custom cell classawakeFromNib中编写或者你应该使用willDisplayCell方法来编写动画。

希望这会有所帮助:)

关于ios - 滚动 uitableviewcell 后 UIView.animateWithDuration 停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37316282/

相关文章:

android - 是否可以封装React Js webApps来构建跨平台的移动应用程序?

iphone - 在 iPad 上播放声音,使用 AudioToolbox

ios - 使用 secItemUpdate 更新 iOS 中的 kSecValueData 错误代码 -50

ios - 如何在 iOS(Swift 或 Objective C)中实现这样的套接字调用?

ios - PFQueryTableViewController "loading"指标查询成功后卡住

ios - 如何在 objective-c 中的 View Controller 上获取自定义TableViewCell值

ios - CocoaPods 在添加新 pod 时出现问题

swift - NSObject.setValue(value : AnyObject? , forKey key : String) implemented? )如何

swift - 为什么转发可变参数无效?

ios - 如何在表格单元格中自动更改标签的大小?