Core animator 1.42/16/2024 You might be working with multiple CALayer subclasses (see Chapter 6, “Specialized Layers”) and have no desire to create new UIView subclasses to host them all.You might be writing cross-platform code that will also need to work on a Mac.You might still want to use a hosted CALayer instead of a layer-backed UIView in a real-world application for a few reasons, however: The benefit of using a layer-backed view instead of a hosted CALayer is that while you still get access to all the low-level CALayer features, you don’t lose out on the high-level APIs (such as autoresizing, autolayout, and event handling) provided by the UIView class. (In Mac OS 10.8, the performance of NSView is greatly improved, as well.) But the lightweight UIView class in iOS barely has any negative impact on performance when working with layers. On Mac OS, prior to version 10.8, a significant performance penalty was involved in using hierarchies of layer-backed views instead of standalone CALayer trees hosted inside a single view. Although it is possible to add layers in this way, more often than not you will simply work with views and their backing layers and won’t need to manually create additional hosted layers. As Listing 1.1 shows, you can explicitly create standalone layers and add them directly as sublayers of the backing layer of a view. layer view has only one backing layer (created automatically) but can host an unlimited number of additional layers. ![]() create sublayer CALayer *blueLayer = īlueLayer. ![]() Adding a Blue Sublayer to the View #import "ViewController.h" #import ViewController ( nonatomic, weak) IBOutlet UIView ViewController You can create a CGColor directly using Core Graphics methods if you prefer, but using UIColor saves you from having to manually release the color when you no longer need it. The CALayer backgroundColor property is of type CGColorRef, not UIColor like the UIView class’s backgroundColor, so we need to use the CGColor property of our UIColor object when setting the color. A small blue CALayer nested inside a white UIView
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |