I have a UICollectionView
. I want to generate two snapshots for each objects.
我有一个UICollectionView。我想为每个对象生成两个快照。
Sample Code:
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.
}
I have written the code in cellForItemAtIndexPath. If there is no image in the path, it will create automatically. So when I launch the application for the first time, the UI is not responsive since there are many snapshots are getting created. This slow down the user interaction. Is there any work around for this?
我已经在cellForItemAtIndexPath中编写了代码。如果路径中没有图像,则会自动创建。因此,当我第一次启动应用程序时,UI没有响应,因为正在创建许多快照。这减缓了用户交互。这有什么工作吗?
1 个解决方案
#1
0
Use drawViewHierarchyInRect
instead of drawInContext
as it's much faster
使用drawViewHierarchyInRect而不是drawInContext,因为它更快
See the iOS 7 example here: https://coderwall.com/p/56wcfq/fast-snapshot-any-views-on-ios-7
请参阅此处的iOS 7示例:https://coderwall.com/p/56wcfq/fast-snapshot-any-views-on-ios-7
#1
0
Use drawViewHierarchyInRect
instead of drawInContext
as it's much faster
使用drawViewHierarchyInRect而不是drawInContext,因为它更快
See the iOS 7 example here: https://coderwall.com/p/56wcfq/fast-snapshot-any-views-on-ios-7
请参阅此处的iOS 7示例:https://coderwall.com/p/56wcfq/fast-snapshot-any-views-on-ios-7