iPad视网膜模拟器中的CATiledLayer性能不佳 [英] CATiledLayer in iPad retina simulator yields poor performance

查看:94
本文介绍了iPad视网膜模拟器中的CATiledLayer性能不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这可能只是模拟器的一个问题,但当然让我担心,因为我已经提交了我的视网膜应用程序,直到16日才能测试它。

I'm hoping maybe this is just an issue with the simulator but of course it has me worried since I have already submitted my retina capable apps and there's no way to test it until the 16th.

我在我的应用程序中实现了一个CATiledLayer来查看非常大的地图。地图的图块来自互联网,但它们也会被缓存,因此,通常它们实际上是直接从设备加载的。

I have implemented a CATiledLayer in my app to view very large maps. The tiles for the map are coming from the internet, however they also get cached, so, typically, they are actually being loaded directly from the device.

在iPad 1和iPad2上它运行得很漂亮。您只能注意到iPad 2上呈现的图块,即使它们来自互联网也是如此。

On iPad 1 and iPad2 it works beautifully. You can only barely notice the tiles being rendered on the iPad 2, even when they are coming from the internet.

在iPad模拟器上它运行得很漂亮。

On the iPad Simulator it works beautifully.

我的问题是iPad视网膜模拟器。在视觉上,它看起来没问题。地图的大小正确,并与我用于显示数据叠加层的另一个图层对齐,但是它会慢慢加载。我尝试的大部分时间,在开始滚动之前根本不会加载任何图块,然后当 加载图块时,它可能每秒执行1次并且看起来很糟糕。

My problem is the iPad retina simulator. Visually, it looks okay. The map is sized properly and lines up with another layer I use to display a data overlay, however it loads INCREDIBLY slowly. Most of the time I try, it won't load any tiles at all until I begin scrolling, then when it is loading tiles it's doing maybe 1 per second and looks terrible.

我没有在视网膜上运行的代码比标准分辨率屏幕不同,所以我希望这只是模拟器的问题......但我仍然担心。

I have no code that would run differently on the retina than the standard resolution screen, so I'm hoping this is just an issue with the simulator...but I'm still concerned.

有没有其他人在他们自己的应用程序中看到过这个?

Has anyone else seen this in their own apps?

推荐答案

更大的瓷砖尺寸对我有用,但是当我调整CATiledLayer的levelsOfDetailBias属性时,它会回到制作小瓷砖并且需要永远加载。关闭细节偏差是不可接受的,因为放大到需要看起来清晰的视图,所以我看了一些Apple的文档 - https://web.archive.org/web/20120323033735/http://developer.apple.com/library /ios/samplecode/ZoomingPDFViewer/Listings/Classes_PDFScrollView_m.html - 他们的一个建议是覆盖平铺视图的layoutSubviews方法,以便始终设置contentScaleFactor = 1.之后我唯一需要做的就是每次scrollViewDidEndZooming触发时调用setNeedsLayout。这假设您使用的是UIScrollView。我已经在我的iPad(第三代)和iPad2上进行了测试,两者似乎都运行良好。希望有所帮助。

Bigger tile sizes were kind of working for me, however when I would adjust the levelsOfDetailBias property of the CATiledLayer, it would go back to making tiny tiles and it would take forever to load. Turning off detail biasing was unacceptable as zooming into the view needed to look sharp, so I looked at some of Apple's docs - https://web.archive.org/web/20120323033735/http://developer.apple.com/library/ios/samplecode/ZoomingPDFViewer/Listings/Classes_PDFScrollView_m.html - and one of their suggestions was to override the layoutSubviews method of your tiled view to always set the contentScaleFactor = 1. The only thing I had to do after that was call setNeedsLayout every time scrollViewDidEndZooming fired. This is assuming you are using a UIScrollView. I have tested this on my iPad(3rd Gen) and iPad2, both seem to work very well. Hope that helps.

示例代码 - 假设您正在继承UIView并使用CATiledLayer覆盖视图的支持层 -

Example Code - Assuming you are subclassing a UIView and overriding the view's backing layer with a CATiledLayer -

     -(void)layoutSubviews{
        [super layoutSubviews];
        /* 
           EDIT: After some additional experimentation, 
           I Have found that you can modify this number to .5 but you need
           to check to make sure you are working on a 3rd gen iPad. This
           seems to improve performance even further.
        */

        // Check if app is running on iPad 3rd Gen otherwise set contentScaleFactor to 1
        self.contentScaleFactor = .5;
    }

然后假设您的View Controller设置为UIScrollViewDelegate -

then assuming your View Controller is setup as a UIScrollViewDelegate -

    -(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{
        //do any other stuff you may need to do.
       [view setNeedsLayout];
    }

这篇关于iPad视网膜模拟器中的CATiledLayer性能不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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