iOS CATiledLayer崩溃 [英] iOS CATiledLayer crash

查看:131
本文介绍了iOS CATiledLayer崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个适用于iPad的pdf阅读器应用程序,我使用滚动视图来显示每个页面。我将页面保持在视图中,并在页面的任一侧查看一页。我有纵向和横向视图的独立视图。纵向视图显示单个页面,横向查看器显示2个页面。

I have a pdf reader app for the iPad where I am using a scrollview to display each page. I keep the page in view and one page either side of the page in view. I have seperate views for portrait and landscape views. The portrait view showns a single page and the landscape viewer shows 2 pages.

当iPad更改方向时,我卸载旧方向的视图并加载新视图方向。所以说它是在纵向视图中然后更改为横向应用程序卸载纵向视图并加载横向视图。这一切都很有效,除非pdf很大。

When the iPad changes orientation I unload the view for the old orientation and load the view for the new orientation. So say it was in portrait view and then changes to landscape the app unloads the portrait view and loads the landscape view. This all works great except when the pdf's are large.

pdf是使用tileslayers绘制的。当方向改变为大pdf时,应用程序正在进行清理。如果在绘制瓷砖之前更改了方向,则应用程序仅会崩溃。我的猜测是它崩溃了,因为它试图将瓷砖绘制到视图而不是已卸载。那么当我卸载视图时有没有办法停止绘制图块?

The pdf's are drawn using tiledlayers. The app is scrashing when the orientation is changed with large pdf's. The app only crashes if the orientation is changed before the tiles have all been drawn. My guess is that it is crashing because it is trying to draw tiles to a view than has been unloaded. So is there a way to stop the drawing of tiles when I unload the view?

推荐答案

您需要将CALayer的委托设置为nil ,然后从superview中删除它。
这会停止渲染,之后你可以安全地解除分类。

You need to set CALayer's delegate to nil, then remove it from the superview. This stops rendering, afterwards you can safely dealloc.

- (void)stopTiledRenderingAndRemoveFromSuperlayer; {
    ((CATiledLayer *)[self layer]).delegate = nil;    
    [self removeFromSuperview];
    [self.layer removeFromSuperlayer];
}

此外,请确保从主线程调用此函数,否则可能会出现错误将等待你。

Also, make sure to call this from the main thread, or else horrible bugs will await you.

这篇关于iOS CATiledLayer崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆