본문 바로가기
프로그래밍 놀이터/iOS

[ios/reference] Core Animation Basics

by 돼지왕 왕돼지 2017. 11. 20.
반응형

 [ios/reference] Core Animation Basics


https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/CoreAnimationBasics/CoreAnimationBasics.html#//apple_ref/doc/uid/TP40004514-CH2-SW3


3차원, anchor point, anchorpoint, animate, animation, animation 중간에 이미지 변경, bounds, cached bitmap, calayer, calayer hierarchy, catransform3d, Coordinate System, core animation, core animation private, Draw, draw content, drawrect, event handle, Expensive, floating point number, FRAME, geometryflipped, HardWare, IMAGE, IOS, Layer, layer property, layer tree, layer-backed, layer-hosting, layer.anchorpoint, layer.position, left bottom, left top, mainthread, matrix multiplcation, Memory, model layer tree, OS X, OSX, point based coordinate, Position, presentation tree, presentationlayer property, print, property, readonly, render tree, responder chain participate, Retina Display, Rotation, Scale, screen 상 좌표, Size, standalone layer, subLayer, sublayertransform, Sync, transform, Translation, unit coordinate, View, view operation, y axis, [ios/reference] Core Animation Basics, 고정, 다른 layer 와의 상대적 좌표, 위치


-

Prerequisite 로 앞의 글들을 읽어보길...

앞의 글들에서 catch 하지 못한 부가 정보들만 정리



-

Core Animation 을 사용하지 않고, 변화에 대해서 drawRect: 에서 다시 그리는 방법도 있지만,

이 방법은 MainThread 에서 그림을 그리기 때문에 매우 expensive 하고, 비효율적이다.


Core Animation 은 Cached Bitmap 과 함께 Hardware 를 사용하여 Animation 하기 때문에 훨씬 효율적이다.



-

Core Animation 은 Layer 와 함께 Cached Bitmap 을 사용하기 때문에, Animation 중간에 이미지를 바꾸는 것은 성능 저하를 야기할 수 있다.



-

Layer 는 View 에는 없는 추가 property 들이 있다.

anchor point 가 대표적 예.



-

Layer 는 두 가지 타입의 Coordinate System 을 사용한다.

point-based coordinate 와 unit coordinate 가 그것이다.


Point-based coordinate 는 screen 상의 좌표 매핑이나, 다른 layer 와의 상대적 값을 설정할 때 사용한다.

이는 layer.position 으로 접근한다.


Unit coordinate 는 screen 과 상관없는 좌표를 설정할 때 사용한다.

0.0 ~ 1.0 사이의 값을 가지며, 이 값은 고정이더라도 절대좌표값으로 보면 값이 바뀔 수 있다.


layer.anchorPoint 는 view 자체의 bounds 와 상관있고, 스크린의 좌표와는 상관이 없다.

Center 지정을 위해 (0.5, 0.5) 를 지정한 경우, 계속 center 를 가르키지만,

position 이나 bounds 등의 값이 바뀌면 절대 좌표 값은 바뀌게 된다.



-

Layer 에는 bounds, position, frame 값이 있다.

bounds 는 size 를 지정한다.

position 은 위치를 지정한다.

frame 은 position 과 bounds 의 조합이라고 보면 된다.



-

position 정보는 iOS 에서는 left top 이 0, 0 이고,

OS X 에서는 left bottom 이 0, 0 이다.



-

y axis 에 대한 방향을 뒤집는 geometryFlipped 란 property 가 있다.

그러나 이 값은 사용하지 않는 것이 좋다.



-

point coordinate 를 사용하던 unit coordinate 를 사용하던 floating-point number 를 사용한다.

floating-point number 를 사용하는 것은 print 할 때나 Retina display 에서 drawing 할 때 유용하다.



-

anchorPoint 는 position 과 transform 을 조작하는 데 영향력이 큰 값이다.

position property 는 항상 layer 의 anchor point 에 영향을 받는다.

transform 은 anchor point 를 기준으로 이루어진다.



-

Layer 는 3차원으로 조작된다.

CALayer 의 transform 에 가하는 것은 그 뿐만 아니라 sublayer 들에도 영향을 미친다.

sublayerTransform 이라는 property 도 있는데, 이 녀석은 sublayer 들에만 적용된다.



-

CATransform3D 를 통해서 아래와 같은 matrix multiplication 을 할 수 있다.

matrix 를 통해서는 scale, translation, rotation 등을 할 수 있다.


3차원, anchor point, anchorpoint, animate, animation, animation 중간에 이미지 변경, bounds, cached bitmap, calayer, calayer hierarchy, catransform3d, Coordinate System, core animation, core animation private, Draw, draw content, drawrect, event handle, Expensive, floating point number, FRAME, geometryflipped, HardWare, IMAGE, IOS, Layer, layer property, layer tree, layer-backed, layer-hosting, layer.anchorpoint, layer.position, left bottom, left top, mainthread, matrix multiplcation, Memory, model layer tree, OS X, OSX, point based coordinate, Position, presentation tree, presentationlayer property, print, property, readonly, render tree, responder chain participate, Retina Display, Rotation, Scale, screen 상 좌표, Size, standalone layer, subLayer, sublayertransform, Sync, transform, Translation, unit coordinate, View, view operation, y axis, [ios/reference] Core Animation Basics, 고정, 다른 layer 와의 상대적 좌표, 위치



-

Core Animation 은 3가지 형태의 layer 를 이용하여 content 를 만든다.


     model layer tree ( layer tree )

          지금까지 다룬 CALayer 의 hierarchy 라고 보면 된다.


     presentation tree

          현재 수행되고 있는 animation 에 대한 값을 가지고 있다. 이 녀석을 modify 하면 안 된다. readonly 처럼 사용하는 것이 좋다.

          presentationLayer property 를 통해 access 가능하다.


     render tree : Core Animation private 한 값으로 실제 animation 을 수행한다.



-

Layer 는 draw 와 animate 를 하는 데 최적화되어있는 녀석이고,

event handle, draw content, responder chain participate 등은 할 수 없다.

 

 

-

iOS 에서는 모든 view 가 layer 를 가지고 있지만(layer-backed), OS X 에서는 layer 를 가질지 선택해줘야 한다. (layer-hosting)

Layer 를 갖는 것은 overhead 가 될 수 있지만, 갖고 있는 것 자체가 엄청난 득이 될 수 있어 잘 선택해야 한다.

layer-backed 의 경우 view 의 상태와 layer 의 상태를 자동으로 sync 해주지만,

layer-hosting 은 그렇지 않다.



-

layer-backed view 에서는 가능한한 layer 대신 view 를 operation 하는 것이 권장된다.



-

standalone Layer 를 사용하는 좋은 case 중 하나는..

image 를 한번만 로드해서 여러 layer 에 모두 setting 하여 memory 절약하는 전략..




반응형

댓글