Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

cocoa - What's the difference and compatibility of CGLayer and CALayer?

I'm confusing CGLayer and CALayer. They look similar, so why are there separate implementations? What's the difference between, and compatibility of, CGLayer and CALayer?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

They are completely different, and not compatible.

To be absolutely clear:

it is strictly a coincidence that the word "layer" is used in both names; they are completely unrelated.

CGLayers are a "special" "high performance" thingy.

You could consider them "like bitmaps, but better."

Apple sat down and said "We're sick of people using bitmaps, let's make something better!" :-)

Indeed, you only work with CGLayers offscreen.

To repeat, CGLayers are entirely used offscreen.

Once they are ready, you can then blast them on to your actual screen (that is to say: blast them on to one of your views).

(However: note that: CGLayers are often used "alone." When I say they are used "alone," I mean they are used for: image processing or mathematical calculations. In that case, CGLayers are never seen onscreen, and they have utterly no connection to the onscreen world.)

In contrast ... CALayers are simply the things "in" views. CALayers are just how views work.

So the two concepts are totally different.

CALayers are just the things "in" views. In contrast CGLayers are Apple's cool "offscreen, high performance, calculation machinery."

To be clear, CGLayers have utterly no connection to views, and no association with views. (Sure, you could paste a CGLayer in to a view, but then, you can paste say "typography" or "an image" in to a view. Typography and images are not views, and CGLayers are not views.)

The typical example is this:

you want to draw something complicated once, and then draw that thing many times on-screen. The answer to that problem is exactly CGLayers. Your "work area" would be a CGLayer; you could then blit it on to a printer, on to the screen, or whatever.

To be clear, in my opinion Apple should have chosen a different name ...

a good name would be "CGCalculationSpace."

The fact that the name contains the word "layer," makes you think of NSLayers.

To repeat: there is absolutely no relationship, whatsoever, in any way. CGLayers are not even vaguely related to layers.

There is no connection, at all. It is really confusing that the letters "l a y e r" are used in the name - it's a shame!!

CGLayers should be called perhaps "workspaces" or "calculation paradigms" or something like that.

Hope it helps and hope you're still reading!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...