Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 卡莱尔表现不佳?_Ios_Performance_Calayer_Lag - Fatal编程技术网

Ios 卡莱尔表现不佳?

Ios 卡莱尔表现不佳?,ios,performance,calayer,lag,Ios,Performance,Calayer,Lag,我已经为这个问题挣扎了好几个星期了。不管怎么说,卡莱尔的很糟糕。它们造成了如此多的延迟,使我的UI看起来更糟 基本上我有一个简单的UITableView,它的效率和滚动时的所有延迟都来自3行代码: CALayer *imageLayer2 = [cell.imageView layer]; [imageLayer2 setMasksToBounds:YES]; [imageLayer2 setCornerRadius:10.0]; 我已尝试将setMaskToBounds设置为否,但没有圆角应

我已经为这个问题挣扎了好几个星期了。不管怎么说,卡莱尔的很糟糕。它们造成了如此多的延迟,使我的UI看起来更糟

基本上我有一个简单的UITableView,它的效率和滚动时的所有延迟都来自3行代码:

CALayer *imageLayer2 = [cell.imageView layer];
[imageLayer2 setMasksToBounds:YES];
[imageLayer2 setCornerRadius:10.0];
我已尝试将setMaskToBounds设置为否,但没有圆角应用于UIImageView。由于某些奇怪的原因,iPad上的问题似乎比iPhone上的问题更严重,但我现在只想找到一个解决办法。此外,此代码位于我的CellForRowatineXpath中,但仅在需要新单元格时执行,因此不总是调用它

不管怎样,你建议我怎么做,而不是使用CALayers来消除这种滞后


谢谢

如果你想弄乱图像本身,你可以把它做成圆形,然后按原样使用, 要将矩形图像更新为圆形矩形图像,请选中此答案
我认为这里的问题是因为每次调用
cellforrowatinex
时都在这样做。我的建议是,用遮罩和角半径存储图像,当您实际需要时,请模型检索图像,而不是再次计算。
cellforrowatinex
是一个合理的位置,您应该避免在其中执行昂贵的操作。

我发现,如果您使用UIImage的CGImageRef,它比直接使用UIImage要快得多

试试这个:

CALayer *imageLayer2.contents = (id)[cell.imageView image].CGImage;
[imageLayer2 setMasksToBounds:YES];
[imageLayer2 setCornerRadius:10.0];

虽然我实际上会完全摆脱ImageView,只处理CALayers和UIImages(假设您不关心可访问性)

您是从哪个方法执行上述代码的?您确定这是导致性能低下的代码吗?你评论过并检查过了吗?@sergio thecellForRowAtIndexPath@qegal是的,我做了三次检查,这就是问题所在。我甚至试过这样做,但滞后仍然存在。还有其他方法吗?在cellforrow中这样做,但不要在view中这样做加载并缓存图像,甚至将它们保存在磁盘上以备将来使用