Core Animation Study Notes

Source: Internet
Author: User

Core AnimationLearning notes are the content of this article.Core AnimationIt has been a while.Core AnimationThere is no good introduction 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 read this article are actually people who understand the interface.AnimationTechnical Principles. 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.

In viewCore AnimationThe content is really complicated, and the application's Objective-C language itself has many features, so I wrote a memorandum to record it. If someone who understands it finds an error after reading it, don't hesitate.

1. UIView is the basis of interface elements in iOS systems. All interface elements are inherited from it. It is completely composedCoreAnimationIn Mac ). The real plot is managed by a class called CALayerCore 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 primary CALayer instance. UIView has a layerClass method that returns the class used by the primary layer and the class of UIView. You can reload this method, to make the UIView display with different CALayer, for example, through

 
 
  1. - (class) layerClass {   
  2.   return ([CAEAGLLayer class]);   
  3. }  

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

 
 
  1. grayCover = [[CALayer alloc] init];   
  2. grayCover.backgroundColor = [[[UIColor blackColor] colorWithAlphaComponent:0.2] CGColor];   
  3. [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 the system maintains three copies. This is a bit difficult to understand ).

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.AnimationOperation

I think this is the case outside the main layer of UIView). When you modify its subLayer, that is, the attributes of the subLayer, the system automatically generates an animation. The animation duration has a default time, my personal experience is about 0.5 seconds. During the animation time, the system automatically determines which attributes have been changed and automatically performsAnimationInterpolation: Generate intermediate frames and display them continuously.AnimationEffect.

6. The relationship between position and anchorPoint in the coordinate system 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.

 
 
  1. 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.

 
 
  1. 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 .....

Summary:Core AnimationThe content of the study notes has been introduced ,. I hope this article will help you!

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.