CALayer 方法屬性整理

/*建立並初始化*/
+ (instancetype)layer;

/*這個初始化方法被coreAnimation 用來建立layer 的陰影 */
- (instancetype)initWithLayer:(id)layer;

 /*返回當前正在顯示的呈現圖層, 動畫被激活以後調用此方法纔有效*/
- (nullable id)presentationLayer;

 /*key 爲須要動畫的屬性, 若是該屬性須要自定義動畫,則調用測方法返回 YES 便可.
  此方法被子類重寫. 對於給定的屬性返回 YES, 若是該屬性的值發生改變(包括附加在 layer 上的動畫使該屬性的值發生改變),則該屬性所在的圖層將會進行重繪.
  若是此方法指定的屬性沒有發生改變, 則應調用父類的此方法[super needsDisplayForKey:key].
*/
+ (BOOL)needsDisplayForKey:(NSString *)key;

/*可動畫屬性: 默認爲CGRectZero, layer 的大小*/
@property CGRect bounds;

/*可動畫屬性, layer 的錨點在 superLayer 中的位置, 錨點默認在試圖的中點位置*/ @property CGPoint position;
/*layer 在 superLayer 中z 方向圖層樹的位置, 默認爲0, 可動畫*/ @property CGFloat zPosition; /*錨點: 圖層的定點, 相對於圖層自己的單位點, 可動畫屬性*/ @property CGPoint anchorPoint; /*應用於 layer 的形變(transform), 依賴於錨點, 默認爲 identityTransform, 可動畫屬性*/ @property CATransform3D transform; /*便利方法 對於訪問 layer 的 transform 屬性 CGAffineTransform類型*/ - (CGAffineTransform)affineTransform; - (void)setAffineTransform:(CGAffineTransform)m; /*隱藏 layer , 不可動畫*/ @property(getter=isHidden) BOOL hidden; /*圖層能夠雙面渲染 , 可動畫屬性*/ @property(getter=isDoubleSided) BOOL doubleSided; /*父圖層*/ @property(nullable, readonly) CALayer *superlayer; /*將 layer 從它的父視圖中移除, 接受對象:1. layer 在父視圖的子視圖數組中,; 2. layer 設置爲父視圖的 mask 屬性*/ - (void)removeFromSuperlayer; /*將 layer 做爲子視圖插入到 接收者的subLayers 中制定的位置 idx, 若是 layer 有父視圖, 則會先將 layer 從父視圖中移除, 再插入到新的父視圖中的位置 idx*/ - (void)insertSublayer:(CALayer *)layer atIndex:(unsigned)idx; /* layer: 被插入的對象, receiver: 將要插入到的父視圖 sibling: 在父視圖中已經存在的子視圖, 若爲 nil (below:將 layer 插入到第一個位置, above: 插入到最後一個位置.   將 layer 插入到父視圖中 sibling 的前面(below)或者後面(above:被當前顯示出來的), 插入前會將 layer 從它的父視圖中移除 */ - (void)insertSublayer:(CALayer *)layer below:(nullable CALayer *)sibling; - (void)insertSublayer:(CALayer *)layer above:(nullable CALayer *)sibling; /*遮罩屬性, layer 定義形狀, 父視圖定義顯示的內容*/ @property(nullable, strong) CALayer *mask;

/*返回 YES 時, 會剪切邊界,*/
@property BOOL masksToBounds; /** Mapping between layer coordinate and time spaces. **/
/*點/時間 或者 Rect 在不一樣座標系之間的轉換*/
- (CGPoint)convertPoint:(CGPoint)p fromLayer:(nullable CALayer *)l; - (CGPoint)convertPoint:(CGPoint)p toLayer:(nullable CALayer *)l; - (CGRect)convertRect:(CGRect)r fromLayer:(nullable CALayer *)l; - (CGRect)convertRect:(CGRect)r toLayer:(nullable CALayer *)l; - (CFTimeInterval)convertTime:(CFTimeInterval)t fromLayer:(nullable CALayer *)l; - (CFTimeInterval)convertTime:(CFTimeInterval)t toLayer:(nullable CALayer *)l; /** Hit testing methods. **/
/*判斷點 p 是否在當前 layer 的座標系中, 在則返回 layer , 不在則返回 nil*/
- (nullable CALayer *)hitTest:(CGPoint)p; /* Returns true if the bounds of the layer contains point 'p'. */ - (BOOL)containsPoint:(CGPoint)p; /** Layer content properties and methods. **/ /* An object providing the contents of the layer, typically a CGImageRef, * but may be something else. (For example, NSImage objects are * supported on Mac OS X 10.6 and later.) Default value is nil. * Animatable. */
/*通常用來設置 layer 的圖片*/
@property(nullable, strong) id contents;
/* Reload the content of this layer. Calls the -drawInContext: method * then updates the `contents' property of the layer. Typically this is * not called directly. */
/*調用此方法會執行 -drawInContext: 方法, 來更新layer 的 contents 屬性, 通常不直接調用此方法*/
- (void)display; /* Marks that -display needs to be called before the layer is next * committed. If a region is specified, only that region of the layer * is invalidated. */
/*UIview 的 setNeedsDisplay 和 setNeedsLayout 方法區別
  1. 兩個方法都是異步執行的, 而 setNeedsDisplay 方法會自動調用 drawRect 方法, 這樣能夠拿到當前的 Context, 就能對 layer 進行從新繪製
  2. setNeedsLayout 會調用 layoutSubViews 方法, 進行對子控件的從新佈局.
*/
- (void)setNeedsDisplay; - (void)setNeedsDisplayInRect:(CGRect)r;
/* Returns true when the layer is marked as needing redrawing. */
/*標記 layer 須要進行從新繪製*/
- (BOOL)needsDisplay; /* Call -display if receiver is marked as needing redrawing. */
/*回調 -displayer 方法, 若是接收者須要進行重繪*/
- (void)displayIfNeeded;

/* When true -setNeedsDisplay will automatically be called when the * bounds of the layer changes. Default value is NO. */ @property BOOL needsDisplayOnBoundsChange;/** Rendering properties and methods. **/ /* Renders the receiver and its sublayers into 'ctx'. This method * renders directly from the layer tree. Renders in the coordinate space * of the layer. * * WARNING: currently this method does not implement the full * CoreAnimation composition model, use with caution. */ - (void)renderInContext:(CGContextRef)ctx;/* The background color of the layer. Default value is nil. Colors * created from tiled patterns are supported. Animatable. */
/*設置背景顏色*/
@property(nullable) CGColorRef backgroundColor; /* When positive, the background of the layer will be drawn with * rounded corners. Also effects the mask generated by the * `masksToBounds' property. Defaults to zero. Animatable. */
/*角半徑: 設置圓角*/
@property CGFloat cornerRadius; /* The width of the layer's border, inset from the layer bounds. The * border is composited above the layer's content and sublayers and * includes the effects of the `cornerRadius' property. Defaults to * zero. Animatable. */
/*設置 layer 的邊界寬度*/
@property CGFloat borderWidth; /* The color of the layer's border. Defaults to opaque black. Colors * created from tiled patterns are supported. Animatable. */
/*設置邊界的顏色, 可動畫*/
@property(nullable) CGColorRef borderColor; /* The opacity of the layer, as a value between zero and one. Defaults * to one. Specifying a value outside the [0,1] range will give undefined * results. Animatable. */
/*layer 的透明度, 可動畫*/
@property float opacity;/** Shadow properties. **/ /* The color of the shadow. Defaults to opaque black. Colors created * from patterns are currently NOT supported. Animatable. */
/*陰影顏色*/
@property(nullable) CGColorRef shadowColor; /* The opacity of the shadow. Defaults to 0. Specifying a value outside the * [0,1] range will give undefined results. Animatable. */
/*陰影透明度*/
@property float shadowOpacity; /* The shadow offset. Defaults to (0, -3). Animatable. */
/*陰影偏移量*/
@property CGSize shadowOffset; /* The blur radius used to create the shadow. Defaults to 3. Animatable. */
/*陰影圓角屬性*/
@property CGFloat shadowRadius; /* When non-null this path defines the outline used to construct the * layer's shadow instead of using the layer's composited alpha * channel. The path is rendered using the non-zero winding rule. * Specifying the path explicitly using this property will usually * improve rendering performance, as will sharing the same path * reference across multiple layers. Upon assignment the path is copied. * Defaults to null. Animatable. */
/*自定義陰影的形狀*/
@property(nullable) CGPathRef shadowPath; /** Layout methods. **//* Marks that -layoutSublayers needs to be invoked on the receiver * before the next update. If the receiver's layout manager implements * the -invalidateLayoutOfLayer: method it will be called. * * This method is automatically invoked on a layer whenever its * `sublayers' or `layoutManager' property is modified, and is invoked * on the layer and its superlayer whenever its `bounds' or `transform' * properties are modified. Implicit calls to -setNeedsLayout are * skipped if the layer is currently executing its -layoutSublayers * method. *//**/ - (void)setNeedsLayout; /* Returns true when the receiver is marked as needing layout. */ - (BOOL)needsLayout; /* Traverse upwards from the layer while the superlayer requires layout. * Then layout the entire tree beneath that ancestor. */ - (void)layoutIfNeeded; /* Called when the layer requires layout. The default implementation * calls the layout manager if one exists and it implements the * -layoutSublayersOfLayer: method. Subclasses can override this to * provide their own layout algorithm, which should set the frame of * each sublayer. */
/*當 layer 須要佈局的時候調用此方法.*/
- (void)layoutSublayers; /** Action methods. **/ /* An "action" is an object that responds to an "event" via the * CAAction protocol (see below). Events are named using standard * dot-separated key paths. Each layer defines a mapping from event key * paths to action objects. Events are posted by looking up the action * object associated with the key path and sending it the method * defined by the CAAction protocol. * * When an action object is invoked it receives three parameters: the * key path naming the event, the object on which the event happened * (i.e. the layer), and optionally a dictionary of named arguments * specific to each event. * * To provide implicit animations for layer properties, an event with * the same name as each property is posted whenever the value of the * property is modified. A suitable CAAnimation object is associated by * default with each implicit event (CAAnimation implements the action * protocol). * * The layer class also defines the following events that are not * linked directly to properties: * onOrderIn * Invoked when the layer is made visible, i.e. either its * superlayer becomes visible, or it's added as a sublayer of a * visible layer * onOrderOut * Invoked when the layer becomes non-visible. */ /* Returns the default action object associated with the event named by * the string 'event'. The default implementation returns a suitable * animation object for events posted by animatable properties, nil * otherwise. */ + (nullable id<CAAction>)defaultActionForKey:(NSString *)event; /* Returns the action object associated with the event named by the * string 'event'. The default implementation searches for an action * object in the following places: * * 1. if defined, call the delegate method -actionForLayer:forKey: * 2. look in the layer's `actions' dictionary * 3. look in any `actions' dictionaries in the `style' hierarchy * 4. call +defaultActionForKey: on the layer's class * * If any of these steps results in a non-nil action object, the * following steps are ignored. If the final result is an instance of * NSNull, it is converted to `nil'. */ - (nullable id<CAAction>)actionForKey:(NSString *)event; /* A dictionary mapping keys to objects implementing the CAAction * protocol. Default value is nil. */ @property(nullable, copy) NSDictionary<NSString *, id<CAAction>> *actions; /** Animation methods. **/ /* Attach an animation object to the layer. Typically this is implicitly * invoked through an action that is an CAAnimation object. * * 'key' may be any string such that only one animation per unique key * is added per layer. The special key 'transition' is automatically * used for transition animations. The nil pointer is also a valid key. * * If the `duration' property of the animation is zero or negative it * is given the default duration, either the value of the * `animationDuration' transaction property or .25 seconds otherwise. * * The animation is copied before being added to the layer, so any * subsequent modifications to `anim' will have no affect unless it is * added to another layer. */ - (void)addAnimation:(CAAnimation *)anim forKey:(nullable NSString *)key; /* Remove all animations attached to the layer. */ - (void)removeAllAnimations; /* Remove any animation attached to the layer for 'key'. */ - (void)removeAnimationForKey:(NSString *)key; /* Returns an array containing the keys of all animations currently * attached to the receiver. The order of the array matches the order * in which animations will be applied. */ - (nullable NSArray<NSString *> *)animationKeys; /* Returns the animation added to the layer with identifier 'key', or nil * if no such animation exists. Attempting to modify any properties of * the returned object will result in undefined behavior. */ - (nullable CAAnimation *)animationForKey:(NSString *)key; /** Miscellaneous properties. **/ /* The name of the layer. Used by some layout managers. Defaults to nil. */ @property(nullable, copy) NSString *name; /* An object that will receive the CALayer delegate methods defined * below (for those that it implements). The value of this property is * not retained. Default value is nil. */ @property(nullable, weak) id delegate; /* When non-nil, a dictionary dereferenced to find property values that * aren't explicitly defined by the layer. (This dictionary may in turn * have a `style' property, forming a hierarchy of default values.) * If the style dictionary doesn't define a value for an attribute, the * +defaultValueForKey: method is called. Defaults to nil. * * Note that if the dictionary or any of its ancestors are modified, * the values of the layer's properties are undefined until the `style' * property is reset. */ @property(nullable, copy) NSDictionary *style; @end /** Action (event handler) protocol. **/ @protocol CAAction /* Called to trigger the event named 'path' on the receiver. The object * (e.g. the layer) on which the event happened is 'anObject'. The * arguments dictionary may be nil, if non-nil it carries parameters * associated with the event. */ - (void)runActionForKey:(NSString *)event object:(id)anObject arguments:(nullable NSDictionary *)dict; @end /** NSNull protocol conformance. **/ @interface NSNull (CAActionAdditions) <CAAction> @end /** Delegate methods. **/ @interface NSObject (CALayerDelegate) /* If defined, called by the default implementation of the -display * method, in which case it should implement the entire display * process (typically by setting the `contents' property). */ - (void)displayLayer:(CALayer *)layer; /* If defined, called by the default implementation of -drawInContext: */ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx; /* Called by the default -layoutSublayers implementation before the layout * manager is checked. Note that if the delegate method is invoked, the * layout manager will be ignored. */ - (void)layoutSublayersOfLayer:(CALayer *)layer; /* If defined, called by the default implementation of the * -actionForKey: method. Should return an object implementating the * CAAction protocol. May return 'nil' if the delegate doesn't specify * a behavior for the current event. Returning the null object (i.e. * '[NSNull null]') explicitly forces no further search. (I.e. the * +defaultActionForKey: method will not be called.) */ - (nullable id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event;
相關文章
相關標籤/搜索