Core Animation 1

Source: Internet
Author: User

/*

Use core animations to import the Quarzcore framework (not required now)

#import <QuartzCore/QuartzCore.h>

The relationship between Calayer and UIView:

1, there is a layer property in UIView as the root layer, the root layer does not have an implicit animation, the root layer can be placed on other sublayers, in UIView all can see the content is contained in the layer

2, Calayer responsible for the content and animation displayed in the view

3. UIView is responsible for monitoring and responding to events

4. Calayer: Included in Quarzcore frame, quarzcore can be used in iOS and Mac OS X

-------------------------------------------------------------------------

The existence meaning of Calayer:

1, Calayer in iOS is designed primarily for content presentation and animation operations, Calayer itself is not included in Uikit, it can not respond to events

2, because Calayer at the beginning of the design to consider its animation operation function, Calayer many properties can be modified to form an animation effect, this property is called "Implicit animation Properties"

-------------------------------------------------------------------------

Common Properties for Calayer:

Define the location of a layer:

Anchorpoint: The description of the anchor point and Anchor Point is the default position in the center point (0.5,0.5) of the image relative to the *x, y position ratio, which determines whether the layer appears in the center position at that point (implicit animation is supported)

BackgroundColor layer Background color Yes (implicit animation is supported)

BorderColor Border Color Yes (implicit animation is supported)

BorderWidth Border Width Yes (implicit animation is supported)

Bounds Layer size Yes (implicit animation is supported)

Contents layers display content, such as the ability to display a picture as a layer content (whether implicit animation is supported)

Contentsrect layer Displays the size and position of the content (whether implicit animation is supported)

Cornerradius Fillet radius Yes (implicit animation is supported)

Doublesided whether the back of the layer is displayed, the default is Yes No (implicit animation is supported)

Frame layer size and position, does not support implicit animations, so frame is seldom used in calayer, usually using bounds and position instead of no (implicit animation is supported)

whether hidden is hidden (implicit animation is supported)

Mask Layer Mask Yes (implicit animation is supported)

Masktobounds Whether a sublayer cuts layer boundaries, default to No Yes (implicit animation is supported)

Opacity transparency, similar to the alpha of UIView (whether implicit animation is supported)

Position determines if the layer is in the parent view's position layer in the parent view * Center point location, similar to UIView's center is (whether implicit animation is supported)

Shadowcolor Shadow color Yes (implicit animation is supported)

Shadowoffset Shadow offset Yes (implicit animation is supported)

Shadowopacity Shadow Transparency, note the default is 0, if setting the shadow must be set this property is (whether implicit animation is supported)

Shadowpath The shape of the shadow (whether implicit animation is supported)

Shadowradius shadow Blur radius Yes (implicit animation is supported)

the sublayers sublayer is

Sublayertransform Sub-layer deformation Yes (implicit animation is supported)

Transform layer Deformation

-------------------------------------------------------------------------

Note: 1. You cannot add gestures on a layer

2, the above support implicit animation property essence is the change of these properties by default implies Cabasicanimation animation implementation

*/

#import "ViewController.h"

#import <QuartzCore/QuartzCore.h>

@interface Viewcontroller ()

{

Calayer *mylayer;

}

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

[Self test1];

[Self layertest];

Self.view.backgroundColor = [Uicolor colorwithred:0.074 green:0.854 blue:0.988 alpha:1.000];

}

-(void) Test1 {

The relationship between Calayer and UIView:

There is a layer property in UIView as the root layer, and other sublayers can be placed on the root layer, and all the visible content in UIView is included in the layer

Calayer responsible for the content and animations displayed in the view

UIView is responsible for monitoring and responding to events

UIView *view = [[UIView alloc]initwithframe:cgrectmake (100, 100, 100, 100)];

View.backgroundcolor = [Uicolor Redcolor];

[Self.view Addsubview:view];

No listening and response events can be added on the layer

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (testresponse:)];

[View Addgesturerecognizer:tap];

}

-(void) Testresponse: (UITapGestureRecognizer *) Sender {

Sender.view.layer.cornerRadius = Sender.view.layer.cornerRadius = = 0? 50:0;

}

#pragma mark-calayer First Experience

-(void) Layertest {

Mylayer = [[Calayer alloc] init];

Mylayer.bounds = CGRectMake (0, 0, 200, 200);

Set Center point

Mylayer.position = Self.view.center;

Mylayer.backgroundcolor = [Uicolor Orangecolor]. Cgcolor;

Mylayer.cornerradius = 100;

Mylayer.borderwidth = 2;

Mylayer.bordercolor = [Uicolor Whitecolor]. Cgcolor;

Mylayer.shadowcolor = [Uicolor Yellowcolor]. Cgcolor;

Mylayer.shadowoffset = Cgsizemake (-1,-5);

Setting the shadow color must first be set shadowopacity (the opacity of the shadow color is 0 completely transparent by default)

Mylayer.shadowopacity = 1.0;

Sub-layers are added to the root layer

[Self.view.layer Addsublayer:mylayer];

Mylayer.delegate = self;

}

-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) Event {

Mylayer.bounds = CGRectMake (0, 0, 300, 300);

Mylayer.backgroundcolor = [Uicolor Greencolor]. Cgcolor;

Mylayer.cornerradius = 150;

}

-(void) touchesended: (Nsset *) touches withevent: (Uievent *) Event {

Uitouch *touch = [touches anyobject];

Mylayer.position = [Touch LocationInView:self.view];

Get the width of the layer

CGFloat width = cgrectgetwidth (mylayer.bounds);

width = width = = 300? 200:300;

Mylayer.bounds = CGRectMake (0, 0, width, width);

Mylayer.cornerradius = WIDTH/2;

Mylayer.backgroundcolor = Mylayer.backgroundcolor = = [Uicolor Orangecolor]. Cgcolor? [Uicolor Greencolor]. Cgcolor: [Uicolor Orangecolor]. Cgcolor;

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}

@end

Core Animation 1

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.