Question

I have been reading a little bit about Core Animation and it's emphasized that a good understanding of CALayer is a must in order to understand it better.

The part that I'm confused with and that may not be so important but I just want to have a better understanding is the fact that apparently there is a very tight connection between CALayer and UIView and apparently every UIView has an underlying CALayer by default, but my question is...

How can CALayer be used in every UIView without having to import the Quartz Core framework, if supposedly, If you want to use CALayer you would need to import the Quartz Core framework first?

I'm assuming that this tight connection between CALayer and UIView happens every time UIView is used, or this only happens when used for animation? If this is the case this would answer my first question and clarify my confusion.

Here are to paragraphs from book "Programming iOS 5 Fundamentals of iPhone" from chapter 16.

"A UIView instance has an accompanying CALayer instance, accessible as the view's layer property."

"Because every view has an underlying layer, there is a tight integration between the two."

Was it helpful?

Solution

A UIView is always backed by a CALayer.

A UIView uses the Quartz Core framework by importing the framework itself. Quartz Core is actually "loaded" but your code can't reference it because the symbols aren't available to your file at compile time.

You could do something like this (it's bad practice, but illustrates that Quartz Core is actually available)

id layer = [self.view performSelector:NSSelectorFromString(@"layer")];
NSArray *filtersOnLayer = [layer performSelector:NSSelectorFromString(@"filters")];

It used to be the case that you had to #import <QuartzCore/QuartzCore.h> in order to interact with layer objects. I'm not sure why, but as of around Xcode 5 that doesn't seem to be the case anymore. It could be related to how Apple changed how they manage precompiled headers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top