我有一个UICollectionView
. 我想为每个对象生成两个快照。
示例代码:
for (int index = 0; index < 2; index++) {
UIView *dummyView = [[UIView alloc] init];
dummyView.frame = some frame....,
dummyView.backgroundColor = [UIColor yellowColor];
UIGraphicsBeginImageContextWithOptions(dummyView.bounds.size, NO, [UIScreen mainScreen].scale);
[dummyView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imgData= UIImageJPEGRepresentation(outputImage, 1.00f);
//Write file.
}
我已经在 cellForItemAtIndexPath 中编写了代码。如果路径中没有图像,它将自动创建。因此,当我第一次启动应用程序时,UI 没有响应,因为正在创建许多快照。这会减慢用户交互。有什么解决方法吗?