Mij*_*ail 5 animation reloaddata ios uicollectionview swift
我正在使用a UICollectionView并reloadItemsAtIndexPaths实现最高效率并免费获得动画.
不知何故,动画有时只会触发(可能会导致重用单元?)我创建了一个简单的项目,其中包含一个UIViewController,一个UICollectionView和一个UIButton来帮助我触发动画.
这是我的代码:
import UIKit
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
var cells = [1]
@IBOutlet weak var sampleCollectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func buttonPressed(sender: AnyObject) {
reloadVisibleSlides()
}
func reloadVisibleSlides() {
self.sampleCollectionView.reloadItemsAtIndexPaths(self.sampleCollectionView.indexPathsForVisibleItems())
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return cells.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell:UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! UICollectionViewCell
cell.backgroundColor = UIColor(hue: CGFloat(arc4random() % 256) / 256.0, saturation: 1, brightness: 1, alpha: 1)
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
如果你编译并运行它,你会看到它只是触发它.
我也试过用它来包围它 performBatchUpdates
有什么我做错了吗?还有另一种方法可以实现吗?
| 归档时间: |
|
| 查看次数: |
1044 次 |
| 最近记录: |