Giter Site home page Giter Site logo

Comments (3)

joshaber avatar joshaber commented on July 23, 2024

Take a look in -[TUIView displayLayer:]. If you don't implement -drawRect: then the view doesn't have to create a backing store. That saves time and memory.

Also note that if your view just needs a background color and nothing else, it's much more efficient to implement that by setting the backgroundColor property instead of implementing -drawRect: and filling manually. That's because CALayer has a built-in fast path for drawing a filled view that also avoids the need to create a backing store.

from twui.

joshaber avatar joshaber commented on July 23, 2024

(And if you come from UIKit land, the same is true there. UIView only creates a backing store if your subclass implements -drawRect:.)

from twui.

mrjjwright avatar mrjjwright commented on July 23, 2024

Oh yes, I read about this in the comments of the Chameleon UIView implementation and how it handles displayLayer and displayLayer:inContect. BigZaphod notes that the basic machinery is as follows:

// Here's how CALayer appears to work:
// 1- something call's the layer's -display method.
// 2- arrive in CALayer's display: method.
// 2a-  if delegate implements displayLayer:, call that.
// 2b-  if delegate doesn't implement displayLayer:, CALayer creates a buffer and a context and passes that to drawInContext:
// 3- arrive in CALayer's drawInContext: method.
// 3a-  if delegate implements drawLayer:inContext:, call that and pass it the context.
// 3b-  otherwise, does nothing

Thanks Josh, this is very helpful to understand when creating simple container views!

from twui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.