0

我有一个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 没有响应,因为正在创建许多快照。这会减慢用户交互。有什么解决方法吗?

4

1 回答 1

0

使用drawViewHierarchyInRect代替,drawInContext因为它更快

在此处查看 iOS 7 示例:https ://coderwall.com/p/56wcfq/fast-snapshot-any-views-on-ios-7

于 2016-01-04T14:36:41.677 回答