我创建了一个自定义let $x = "id"
return $table/@*[local-name(.) = $x]
let $x := xs:QName("id")
return $table/@*[node-name(.) = $x]
并且表现不佳。我首先认为这是我的布局的一个问题,但经过大量的调试后,似乎问题出在UICollectionViewFlowLayout
本身。能够以一个非常简单的例子重新创建它:
UICollectionView
每当我更改import UIKit
private let reuseIdentifier = "Cell"
class CollectionViewController: UICollectionViewController {
private let numCells = 12
private let numSections = 120
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView?.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 1)
self.collectionView?.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return numSections
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return numCells
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
cell.backgroundColor = UIColor(hue: CGFloat(indexPath.section) / CGFloat(numSections), saturation: 1 - CGFloat(indexPath.item) / CGFloat(numCells), brightness: 1, alpha: 1)
return cell
}
}
public class MyLayout: UICollectionViewFlowLayout {
public override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
print("attributes \(rect)")
return super.layoutAttributesForElementsInRect(rect)
}
}
时,每次滚动更新时都会调用contentInset.right > 0
两次,而不是每次我接近{ {1}}还不知道。为什么会发生这种情况,有没有办法避免这些更新?
更新
我确实对该示例进行了分析,并且只要layoutAttributesForElementsInRect
设备使用的CPU时间显着增加
UICollectionView
这似乎是一种内部方法。