什么触发屏幕渲染,混合和layoutSubviews在iOS中? [英] What triggers offscreen rendering, blending and layoutSubviews in iOS?

查看:119
本文介绍了什么触发屏幕渲染,混合和layoutSubviews在iOS中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该注意什么性能关键的事情?



我想要一个尽可能多的示例列表。

解决方案

在屏幕上渲染/渲染CPU


$ b $



屏幕外观渲染(软件版本)在屏幕上呈现和混合 - 它们可以在动画的每一帧中发生,渲染)发生在需要在软件(屏幕外)中进行绘制之前,才能被移交到GPU。硬件不处理文字渲染和带遮罩和阴影的高级合成。



以下将触发屏幕呈现:








混合 h2>


  • resizableImage 可能会导致混合。

    在iOS上使用resizableImages时避免混合图层


  • 不是 opaque 且有 backgroundColor code> alpha 小于1.0


  • alpha 小于1.0


  • 任何包含 layer.content 的图层或任何 UIImageView




  • $ b b


    布局



    以下内容会触发 layoutSubviews 要在UIView上调用:




    • 更改 bounds

    • 在同一视图和超级视图上更改框架触发器
    • 在superview上更改转换 layer.transform 触发

      / li>


    注意:我指的是实际值正在改变的实际变化。



    矛盾这些更改不会触发 layoutSubviews 被调用: center layer.position layer.zPosition layer.anchorPoint layer.anchorPointZ



    参考: https://github.com / hfossli / LayoutSubviews不一致






    改善效果的一般提示




    • 通常情况下,混合渲染屏幕


    • 考虑使用 drawRect:,而不是使用多个标签和子视图。 p>


    • 在背景队列上绘制 UIImage CGImageRef


    • 绘制 CGLayer GPU 相比 UIImage ),并绘制任何你想要的。

      更新,不要: http://iosptl.com/posts/cglayer-no-longer-recommended/


    • 整理您的层次结构


    • 重复使用视图 - 滚动时不要创建和添加新

    • p>避免将 alpha layer.opacity 设置为小于1.0


    • 启用 layer.shouldRasterize (小心使用)。我喜欢避免这个个人,但它在某些场合执行更快,因为图层的栅格将被缓存和重用。请记住,如果您在频繁更改其内容或子图层内容的图层上启用 shouldRasterize ,则会导致性能下降,因为iOS会在每次更改时继续对图层进行栅格化。







    链接




    Excactly what performance crtitical things should I have an eye out for?

    I want a list with as many examples as possible. Or a list of best practice.

    解决方案

    Offscreen rendering / Rendering on the CPU

    The biggest bottlenecks to graphics performance is offscreen rendering and blending – they can happen for every frame of the animation and can cause choppy scrolling.

    Offscreen rendering (software rendering) happens when it is necessary to do the drawing in software (offscreen) before it can be handed over to the GPU. Hardware does not handles text rendering and advanced compositions with masks and shadows.

    The following will trigger offscreen rendering:

    • Any layer with a mask (layer.mask)

    • Any layer with layer.masksToBounds / view.clipsToBounds being true

    • Any layer with layer.allowsGroupOpacity set to YES and layer.opacity is less than 1.0
      When does a view (or layer) require offscreen rendering?

    • Any layer with a drop shadow (layer.shadow*).
      Tips on how to fix: https://markpospesel.wordpress.com/tag/performance/

    • Any layer with layer.shouldRasterize being true

    • Any layer with layer.cornerRadius, layer.edgeAntialiasingMask, layer.allowsEdgeAntialiasing

    • Any layer with layer.borderWith and layer.borderColor?
      Missing reference / proof

    • Text (any kind, including UILabel, CATextLayer, Core Text, etc).

    • Most of the drawing you do with CGContext in drawRect:. Even an empty implementation will be rendered offscreen.


    Blending

    • resizableImage can cause blending.
      Avoiding blended layers when using resizableImages on iOS

    • Any layer which is not opaque and has a backgroundColor with alpha less than 1.0

    • Any layer with alpha less than 1.0

    • Any layer with layer.content or any UIImageView with a UIImage having an alpha channel


    Layout

    The following things will trigger layoutSubviews to be called on a UIView:

    • Changing bounds triggers on same view and superview

    • Changing frame triggers on same view and superview

    • Changing transform or layer.transform triggers on superview

    Note: I'm referring to real changes where values actually is changing

    Contradictory these changes does not trigger layoutSubviews to be called: center, layer.position, layer.zPosition, layer.anchorPoint, layer.anchorPointZ.

    Reference: https://github.com/hfossli/LayoutSubviewsInconsistency


    General tips for improving performance

    • Often times it is better to blend than to render offscreen.

    • Consider using drawRect: instead of having a view with multiple labels and subviews.

    • Draw on a background queue to a UIImage or CGImageRef.

    • Draw to a CGLayer (which is cached better on GPU compared to UIImage), and draw whatever you want into it.
      Update, don't: http://iosptl.com/posts/cglayer-no-longer-recommended/

    • Flatten your hierarchy

    • Reuse views – don't create and add new ones while scrolling

    • Have opaque views with solid background color

    • Avoid setting alpha and layer.opacity to less than 1.0

    • Enable layer.shouldRasterize (use with care). I like to avoid this personally, but it performs faster in some occasions since rasters of the layer will be cached and reused. Remember if you enable shouldRasterize on layers that changing their content or sublayers contents frequently will cause the performance to drop, since iOS will keep rasterizing the layer on each change.


    Links

    这篇关于什么触发屏幕渲染,混合和layoutSubviews在iOS中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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