view.layer • Base layer class • Manage and animate visual content • Layers have properties ◦ Most automatically animated • Can add additional animations
layer.contents = UIImage(named: … ) • No pixelation, no clipping, and preserves aspect ratio • Can change line thickness and dashing, how lines end or join other lines, and line and fill color • Great animation support • Use UIBezierPath for easy CGPath creation CAShapeLayer
of copies • Applies a transform to each copy • Can delay drawing of each copy • Can preserve depth • Configure instance: ◦ instanceCount, instanceTransform, instanceDelay
label = UILabel(frame: gradientView.frame) gradientView.addSubview(label) label.text = "Okay - now let’s mask the gradient with the label… “What?” some of you are certainly saying just now. Well - just give it a try, will you?" label.numberOfLines = 0 label.font = UIFont.systemFontOfSize(60) gradientLayer.mask = label.layer
CAEmitterCell • Draw particles above backgroundColor and border • Can change render mode and emitter position, shape, size, spin, velocity, birth rate, and lifetime • Can preserve depth to render in 3D • Can change cell contents, color, speed of color change, scale, emission latitude/longitude, initial velocity, acceleration, birth date, lifetime, magnification/minification filters
sublayers are rendered • Does not flatten its sublayers • Each sublayer has its own opacity • Transform is applied to sublayers • Transform ignores changes to rendered layer properties • Cannot directly hit-test ◦ but can hit-test sublayers
lock horizontal and/or vertical • UIScrollView doesn’t use it • Cannot directly react to touch or bounds check • Use UIScrollView when scrolling is touch-based ◦ Instead it directly changes its layer’s bounds • Use CATiledLayer when scrolling large images
get cool effects into your app • Layers have great support for animation • CALayer are often the foundation for custom iOS controls • AsyncDisplayKit takes advantage of CALayer to update UI in background Playground:https://docs.google. com/presentation/d/1j5vK14VfotpUfmxzpEJO8CpFmDora1gW50Nkfs9o9hQ/edit#slide=id.p Presenation:https://github.com/dimacheverda/CALayerPlayground