Question

I'm trying to extend C4 a bit, and am trying to figure out how gestures and animations work on C4Shape objects. I've looked through the source, and it looks like they are all based on CAShapeLayers, to which gesture recognizers cannot be directly attached. Could someone explain how this works in C4?

Was it helpful?

Solution

Right, all visible objects in C4 are based on a subclass CALayer. For instance, C4Shapes subclass C4ShapeLayers, whereas C4Movies subclass C4PlayerLayer (a subclass of AVPlayerLayer which is already a subclass of CALayer), and images are drawn as the content of a basic CALayer.

However, each one of these layers is contained within a subclass of UIControl (UIView) so that they can all individually register touches and to which they can all have gesture recognizers attached.

As an example, the hierarchy for a C4Shape is:

UIView > UIControl > C4Control (with a C4ShapeLayer as its main layer).

For a movie:

UIView > UIControl > C4Control (with an C4PlayerLayer as its main layer).

etc.

So, all visible objects have the following:

UIView > UIControl > C4Control

... with custom layers for the C4Control object.

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