IOS Core Animation learning Summary (2) -- Implement custom layers, iosanimation

Source: Internet
Author: User

IOS Core Animation learning Summary (2) -- Implement custom layers, iosanimation

1. Create a layer that inherits from CALayer and implements the drawInContext method in the subclass.

@ Interface CTLayer: CALayer @ end @ implementation CTLayer-(void) drawInContext :( CGContextRef) ctx {
// Draw a circle CGContextSetRGBFillColor (ctx, 0, 0, 1, 1); CGContextAddEllipseInRect (ctx, CGRectMake (100,100,100,100); CGContextFillPath (ctx);} @ end

When viewcontroller loads a view,

CTLayer * layer = [CTLayer layer]; layer. bounds = CGRectMake (0, 0,300,300); layer. anchorPoint = CGPointMake (0, 0); [layer setNeedsDisplay]; // display layer [self. view. layer addSublayer: layer];

 

Ii. Create Using proxy

CTLayer * layer = [CTLayer layer]; layer. bounds = CGRectMake (0, 0,300,300); layer. anchorPoint = CGPointMake (0, 0); layer. delegate = self; // specifies the proxy, which can be any type of [layer setNeedsDisplay]; // display layer [self. view. layer addSublayer: layer];

Implement proxy Methods

# Pragma mark proxy method-(void) drawLayer :( CALayer *) layer inContext :( CGContextRef) ctx {CGContextSetRGBFillColor (ctx, 0, 0, 1, 1); CGContextAddEllipseInRect (ctx, CGRectMake (100,100,100,100); CGContextFillPath (ctx );}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.