Clear CATiledLayers Cache When Changing Images

旧巷老猫 提交于 2019-11-29 20:09:03

问题


I have a UIScrollView with a single subview, a UIView backed by a CATiledLayer. All is working well with one exception: when I change images from one to another the CATiledLayer caches the previous images zoom levels. Scrolling around then displays the old image for a split second before the updated image loads.

Is there any way to totally clear out the CATiledLayer's cache so it doesn't show old images? The CATiledLayer obviously knows that the backing image changed because it asks it's delegate for new tiles...


回答1:


I think you are making this a little more complicated than it needs to be. I believe all you have to do is set the contents of your CATiledLayer to nil.

myCATiledlayer.contents = nil.



回答2:


-(void)invalidate
{
    CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];

    tiledLayer.tileSize = CGSizeMake(93,93);//Set a different tile size
    tiledLayer.tileSize = CGSizeMake(92,92);//Restore original tile size
}

This works for me.



来源:https://stackoverflow.com/questions/1274680/clear-catiledlayers-cache-when-changing-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!