简体   繁体   English

iPad视网膜模拟器中的CATiledLayer性能不佳

[英]CATiledLayer in iPad retina simulator yields poor performance

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. 我希望也许这只是模拟器的一个问题,但当然它让我担心,因为我已经提交了我的视网膜应用程序,直到16日才能测试它。

I have implemented a CATiledLayer in my app to view very large maps. 我在我的应用程序中实现了CATiledLayer来查看非常大的地图。 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. 地图的图块来自互联网,但它们也会被缓存,因此,通常它们实际上是直接从设备加载的。

On iPad 1 and iPad2 it works beautifully. 在iPad 1和iPad2上,它的工作非常漂亮。 You can only barely notice the tiles being rendered on the iPad 2, even when they are coming from the internet. 您只能注意到iPad 2上呈现的图块,即使它们来自互联网也是如此。

On the iPad Simulator it works beautifully. 在iPad模拟器上它工作得很漂亮。

My problem is the iPad retina simulator. 我的问题是iPad视网膜模拟器。 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. 大部分时间我尝试了一次,直到我开始滚动它不会加载任何瓷砖的话,那么当它装载瓷砖它在做什么,也许1每秒看起来很可怕。

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? 有没有其他人在自己的应用程序中看到过这个

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. 更大的瓷砖尺寸对我来说很有用,但是当我调整CATiledLayer的levelsOfDetailBias属性时,它会回到制作小瓷砖并且需要永远加载。 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. 关闭细节偏差是不可接受的,因为放大视图需要看起来很清晰,所以我看了一些Apple的文档 - https://web.archive.org/web/20120323033735/http://developer.apple.com/library /ios/samplecode/ZoomingPDFViewer/Listings/Classes_PDFScrollView_m.html - 他们的一个建议是覆盖你的平铺视图的layoutSubviews方法,以便始终设置contentScaleFactor = 1.我之后唯一需要做的就是每次都调用setNeedsLayout scrollViewDidEndZooming已解雇。 This is assuming you are using a UIScrollView. 这假设您使用的是UIScrollView。 I have tested this on my iPad(3rd Gen) and iPad2, both seem to work very well. 我在我的iPad(第三代)和iPad2上进行了测试,两者似乎都运行良好。 Hope that helps. 希望有所帮助。

Example Code - Assuming you are subclassing a UIView and overriding the view's backing layer with a CATiledLayer - 示例代码 - 假设您正在为UIView创建子类并使用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;
    }

then assuming your View Controller is setup as a UIScrollViewDelegate - 然后假设您的View Controller设置为UIScrollViewDelegate -

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

The performance on iPad3 of all TiledLayers is worse than on iPad2 - that's also visible in the GoogleMaps app. iPad3上所有TiledLayers的性能都比iPad2差 - 这在GoogleMaps应用中也很明显。

However, the best performance you get by adding the following changes to your UIView class that uses CATiledLayer 但是,通过向使用CATiledLayer的UIView类添加以下更改可获得最佳性能

- (id)initWithFrame:(CGRect)frame tileSize:(CGSize)tileSize
{
    self = [super initWithFrame:frame];
    if(self)
    {
        CATiledLayer *animLayer = (CATiledLayer *) self.layer;
        animLayer.levelsOfDetail = 5;
        animLayer.levelsOfDetailBias = 3;
        animLayer.tileSize = tileSize;

        // adjustments for retina displays
        if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00)
        {
            animLayer.contentsScale = 1.0;
            self.contentScaleFactor = .5;
            animLayer.shouldRasterize = NO;
            animLayer.levelsOfDetailBias ++;
        }
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00)
    {
        self.contentScaleFactor = .5;
    }
}

There are other options to achieve the same result visually ie increasing tileSize but the performance will be much worse. 还有其他选项可以直观地实现相同的结果,即增加tileSize但性能会更差。

CATiledLayer performance on the simulator seems to be nothing like that of that on an actual new iPad. 模拟器上的CATiledLayer性能似乎与实际新iPad上的性能完全不同。 Test on actual hardware. 测试实际硬件。

CATiledLayer generates a lot more tiles on the new iPad than on older devices, even when using the same settings. 与旧设备相比,CATiledLayer在新iPad上生成的瓷砖要多得多,即使使用相同的设置也是如此。 At the moment I detect whether the code is running on a hires screen (via CALayer's contentScale property), and if so, set a bigger tile size. 目前,我检测代码是否在招聘屏幕上运行(通过CALayer的contentScale属性),如果是,则设置更大的磁贴大小。

I'll be doing more experimentation, and will post any significant findings here. 我将做更多的实验,并将在此发布任何重要的发现。

Remember, it's just a simulator and it's most likely software accelerated. 请记住,它只是一个模拟器 ,它很可能是软件加速的。 On the other hand, the device is hardware accelerated and Core Animation is highly optimized, since there are only few target GPUs to look for. 另一方面,该设备是硬件加速的,并且Core Animation经过高度优化,因为只需要很少的目标GPU。

Until you check your performance on the new iPad itself I wouldn't be concerned with simulator results. 在你检查新iPad本身的性能之前,我不会关心模拟器的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM