Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction To Core Animation (CocoaConf Chica...

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
corvino
March 27, 2015

Introduction To Core Animation (CocoaConf Chicago March 2015)

corvino

March 27, 2015

Transcript

24 slides
  1. UIView Animations [UIView animateWithDuration:1.2 animations:^{ self.targetView.bounds = CGRectMake(0., 0., 100.,

    100.); self.targetView.center = CGPointMake(50., 50); self.targetView.backgroundColor = [UIColor redColor]; self.targetView.alpha = 0.5; }];
  2. • anchorPoint • backgroundColor • backgroundFilters • borderColor • borderWidth

    • bounds • compositingFilter • contents • contentsRect • cornerRadius • doubleSided • filters • hidden • mask • masksToBounds • opacity • position • shadowColor • shadowOffset • shadowOpacity • shadowPath • shadowRadius • sublayers • sublayerTransform • transform • zPosition
  3. • anchorPoint • backgroundColor • backgroundFilters • borderColor • borderWidth

    • bounds • compositingFilter • contents • contentsRect • cornerRadius • doubleSided • filters • hidden • mask • masksToBounds • opacity • position • shadowColor • shadowOffset • shadowOpacity • shadowPath • shadowRadius • sublayers • sublayerTransform • transform • zPosition • frame
  4. • anchorPoint • backgroundColor • backgroundFilters • borderColor • borderWidth

    • bounds • compositingFilter • contents • contentsRect • cornerRadius • doubleSided • filters • hidden • mask • masksToBounds • opacity • position • shadowColor • shadowOffset • shadowOpacity • shadowPath • shadowRadius • sublayers • sublayerTransform • transform • zPosition
  5. • anchorPoint • backgroundColor • backgroundFilters • borderColor • borderWidth

    • bounds • compositingFilter • contents • contentsRect • cornerRadius • doubleSided • filters • hidden • mask • masksToBounds • opacity • position • shadowColor • shadowOffset • shadowOpacity • shadowPath • shadowRadius • sublayers • sublayerTransform • transform • zPosition
  6. • anchorPoint • backgroundColor • backgroundFilters • borderColor • borderWidth

    • bounds • compositingFilter • contents • contentsRect • cornerRadius • doubleSided • filters • hidden • mask • masksToBounds • opacity • position • shadowColor • shadowOffset • shadowOpacity • shadowPath • shadowRadius • sublayers • sublayerTransform • transform • zPosition
  7. UIView Animations [UIView animateWithDuration:1.0 animations:^{ … }]; [UIView animateWithDuration:1.2 delay:0.

    options:UIViewAnimationOptionCurveEaseInOut animations:^{ … } completion:^(BOOL finished) { … }];
  8. UIView Animations [UIView animateWithDuration:1.2 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{ … } completion:^(BOOL

    finished) { [UIView animateWithDuration:1.2 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{ … } } completion:^(BOOL finished) { … } }]; Chain Animations
  9. Explicit Animations CABasicAnimation *theAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"]; theAnimation.fromValue = [NSValue

    valueWithCGRect:self.targetView.bounds]; theAnimation.toValue = [NSValue valueWithCGRect:newBounds]; theAnimation.duration = 1.2; [self.targetView.layer addAnimation:theAnimation forKey:@"AnimateFrame"]; self.targetView.bounds = newBounds; CABasicAnimation
  10. CALayer Subclasses • CAShapeLayer • CATiledLayer • CATextLayer • AV

    Layers (CACaptureVideoPreviewLayer, AVPlayerLayer, etc.) • CAGradientLayer • CATextLayer
  11. CAShapeLayer CAShapeLayer *shape = [CAShapeLayer layer]; shape.frame = someFrame; shape.strokeColor

    = [UIColor greenColor].CGColor; shape.lineWidth = 3.; shape.fillColor = [UIColor yellowColor].CGColor; shape.path = CGPathCreateWithEllipseInRect( CGRectMake(0., 0., someFrame.size.width, someFrame.size.height), &CGAffineTransformIdentity);
  12. CATiledLayer SomeTiledLayerDelegate *tiledDelegate = [[SomeTiledLayerDelegate alloc] init]; CATiledLayer *tiledLayer =

    [CATiledLayer layer]; tiledLayer.delegate = tiledDelegate; tiledLayer.frame = CGRectMake(...); tiledLayer.contentsScale = [[UIScreen mainScreen] scale]; @implementation SomeTiledLayerDelegate - (void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context { CGRect box = CGContextGetClipBoundingBox(context); // ... } @end
  13. Best Practices • Avoid offscreen rendering—Simulator shows • shouldRasterize can

    help; it can also hurt. • Blending is still expensive.

More Decks by corvino

Other Decks in Technology