【发布时间】:2015-12-13 15:07:34
【问题描述】:
我有一个 UITableViewCell,它包含一个 UIView,当 TableViewCell 的 awakeFromNib() 被调用时,它正在被动画化。 动画确实适用于 TableViewController 出现时调用的单元格,但滚动时生成的单元格根本不移动。 我该如何解决这个问题? I added an example on Github to demonstrate the issue.
TableViewController
import UIKit
class ViewController: UITableViewController {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TableViewCell
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
TableViewCell
import UIKit
class TableViewCell: UITableViewCell {
@IBOutlet weak var animatorCell: UIView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
UIView.animateWithDuration(0.3, delay: 0.0, options: [.CurveEaseInOut, .Repeat, .Autoreverse], animations: { () -> Void in
self.animatorCell.transform = CGAffineTransformMakeTranslation(0, 10)
}, completion: nil)
}
}
【问题讨论】:
标签: ios swift uiview uiviewanimation tableviewcell