UITableView不同cell的延时动画
Delay animation of different cells of UITableView
我正在使用 swift 制作应用程序。
我有一个包含 5 个不同行的 UITableView。
我在 table 的每一行上都有一个 UILabel。 (此标签提供行的标题)
此 UILabel 是动画的,因此它在每一行上从左到右进入屏幕。
我的问题是,当我 运行 我的动画时,所有 5 个 UILabel 同时进入它们的行。我想在每个 UILabels 动画之间放置一个延迟。那就是我想让第一行的UILabel先进入屏幕,然后1秒后我想让第二行的UILabel进入屏幕,然后1秒后第三个UILabel ...等等
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell!
let imageView = cell.viewWithTag(1) as! UIImageView
imageView.image = UIImage(named: imageArray[indexPath.row])
let imageText = cell.viewWithTag(2) as! UILabel
imageText.text = sectionName[indexPath.row]
imageText.textAlignment = .Center
//starting position for animation of imageText
imageText.center.x = self.view.frame.width - 500
//animating UILables comming into screen
UIView.animateWithDuration(3, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: ({
imageText.center.x = ((self.view.frame.width) / 1)
}), completion: nil)
return cell
}
添加基于索引路径的延迟。延迟中的 1 是你想要的动画之间的秒数。
let delay = 1 * indexPath.row
UIView.animateWithDuration(3, delay: delay, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: ({
imageText.center.x = ((self.view.frame.width) / 1)
}), completion: nil)
我假设这 5 行是 table 视图需要显示的全部内容,并且所有内容始终显示在屏幕上,这意味着您无需考虑如何处理行滚动时的动画。如果考虑滚动,那么这可能需要更改为仅在 table 视图最初显示时显示动画。
我正在使用 swift 制作应用程序。 我有一个包含 5 个不同行的 UITableView。 我在 table 的每一行上都有一个 UILabel。 (此标签提供行的标题) 此 UILabel 是动画的,因此它在每一行上从左到右进入屏幕。
我的问题是,当我 运行 我的动画时,所有 5 个 UILabel 同时进入它们的行。我想在每个 UILabels 动画之间放置一个延迟。那就是我想让第一行的UILabel先进入屏幕,然后1秒后我想让第二行的UILabel进入屏幕,然后1秒后第三个UILabel ...等等
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell!
let imageView = cell.viewWithTag(1) as! UIImageView
imageView.image = UIImage(named: imageArray[indexPath.row])
let imageText = cell.viewWithTag(2) as! UILabel
imageText.text = sectionName[indexPath.row]
imageText.textAlignment = .Center
//starting position for animation of imageText
imageText.center.x = self.view.frame.width - 500
//animating UILables comming into screen
UIView.animateWithDuration(3, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: ({
imageText.center.x = ((self.view.frame.width) / 1)
}), completion: nil)
return cell
}
添加基于索引路径的延迟。延迟中的 1 是你想要的动画之间的秒数。
let delay = 1 * indexPath.row
UIView.animateWithDuration(3, delay: delay, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: ({
imageText.center.x = ((self.view.frame.width) / 1)
}), completion: nil)
我假设这 5 行是 table 视图需要显示的全部内容,并且所有内容始终显示在屏幕上,这意味着您无需考虑如何处理行滚动时的动画。如果考虑滚动,那么这可能需要更改为仅在 table 视图最初显示时显示动画。