Core animation learning memorandum (Day 1)

Source: Internet
Author: User

We have been studying Core Animation for some time. There is no good introduction to Core Animation on the Internet. There is a special summative introduction on the Apple website, but it seems that there are not many things of the principle. People who see the things are confused and feel that they write the things, in fact, it is assumed that the reader understands the principles of the interface animation technology. Today, we have something to do with Linux. I forgot the ssh password and couldn't reset ssh. I couldn't remember how to set up ssh remote login, I couldn't find it on the Internet again. It was a waste of time and it was terrible to forget to take notes. Given that the Core Animation content is really complicated and the Obj-C language itself has many features, write a memorandum to record it. If an error is found after reading it, don't hesitate to advise.

 

1. UIView is the basis of interface elements in iOS systems. All interface elements are inherited from it. It is fully implemented by CoreAnimation (it does not seem like this in Mac ). The real plot is managed by a class called CALayer (Core Animation Layer. UIView itself is more like a CALayer manager, accessing its properties related to plotting and coordinates, such as frame and bounds, in fact, they are all accessing the relevant attributes of CALayer.

 

2. UIView has a layer attribute that can return its main CALayer instance. UIView has a layerClass method that returns the class used by the main layer. The class of UIView can be reloaded, to make the UIView display with different CALayer, for example, through

- (class) layerClass {  return ([CAEAGLLayer class]);}

Use GL to draw a subclass of A UIView.

 

3. The CALayer of the UIView is similar to the sub-View tree structure of the UIView. You can also add a sub-layer to its layer to complete some special representations. For example, the following code

grayCover = [[CALayer alloc] init];grayCover.backgroundColor = [[[UIColor blackColor] colorWithAlphaComponent:0.2] CGColor];[self.layer addSubLayer: grayCover];

A black transparent film is added to the target View.

 

4. The layer tree of the UIView is inside the system, and three copies are maintained by the system (This section is a bit inaccurate ).

First, the logic tree can be manipulated in the Code, such as modifying the layer attributes.

The second part is the animation tree, which is an intermediate layer where the system is modifying attributes and performing various rendering operations.

The third part is the display tree. The content of this tree is the content currently being displayed on the screen.

The logical structure of these three operators is the same, with only their respective properties.

 

5. animation operation

In addition to the main layer of the UIView (I think this is the case), the system will automatically animated the changes to its subLayer, that is, the attributes of the subLayer, the animation duration has a default time, which is about 0.5 seconds. During the animation time, the system automatically determines which attributes have been changed, automatically performs animation Interpolation on the changed attributes, generates intermediate frames, and then displays them continuously to produce the animation effect.

 

6. Coordinate System (the relationship between position and anchorPoint is still dizzy)

The coordinate system of CALayer is a little different from that of UIView. It has an attribute called anchorPoint, which uses the CGPoint structure, but the value range is 0 ~ 1, that is, set according to the proportion. This point is the coordinate origin of various graphic transformations. It also changes the position of the layer. Its default value is {0.5, 0.5}, that is, in the center of the layer.

A layer. anchorPoint = CGPointMake (0.f, 0.f );

If this is set, the upper left corner of the layer will be moved to the original center,

Just add this sentence.

A layer. position = CGPointMake (0.f, 0.f );

 

7. Analysis of real examples

 

This is The iBook flip on the iphone. If every page is a UIView, I think there are two layers on one page, and the text Layer displays the front content, the back layer uses the snapshot of the text layer to flip the affine and paste it behind the text layer. Because you can set a shadow for a Layer, you may not use a single layer for the shadow effect. As for the surface effect, I checked a lot of information and did not have any results. Is it estimated that the GL curved surface plot was used?

 

8. The last one is disgusting.

You can set the rounded corner display for a layer, such as the UIButton effect or shadow display. However, if a layer in the layer tree sets the rounded corner, the shadow effects of all layers in the tree cannot be displayed. If you want to have a rounded corner and a shadow, you can only create two overlapping uiviews. One layer displays the rounded corner and the other layer displays the shadow .....

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.