【发布时间】:2015-01-27 20:25:44
【问题描述】:
我正在创建一个带有自定义图像的表情符号键盘,它有 845 个不同的图像(如果包含 @1x、@2x 和 @3x,则为 2535 个)。将它们作为资产导入 Xcode 后,现在编译我的程序非常慢,并且在 iOS 模拟器中显示键盘需要 3 秒。
我用来显示表情符号的 UICollectionView 也有问题:滚动时它崩溃了。我试图将我的 UICollectionViewCell 限制为 UIView,其背景是表情符号,这样我就不会创建 UIImageView 但性能仍然很差。
这是我的 cellForItemAtIndexPath() 函数:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as UICollectionViewCell
let emoji = UIImage(named: emojiCollections[collectionUsed][positionInCollection]) // Creating the UIImage with the asset
let emojiBackgroundColor = UIColor(patternImage: emoji!) // Set the background of the cell.
positionInCollection++
return cell
}
对于这些问题,我想知道管理这些图像数量的最佳方法是什么,以及如何在 UICollectionView 中正确显示它们(即具有良好的滚动性能)。
谢谢!
【问题讨论】:
-
边走边加载,避免资产目录
标签: ios xcode swift uiimage uicollectionview