一、基本屬性
----------初始化? ?
?+ (instancetype)layer;? ?
?- (instancetype)init;? ??
- (instancetype)initWithLayer:(id)layer;? ??
----------其它方法? ??
+ (nullable id)defaultValueForKey:(NSString *)key;//返回這個屬性名所對應的屬性值的默認值,如果默認值是未知的,則返回nil,子類可以重載這個方法,來設定一些默認值。? ??
+ (BOOL)needsDisplayForKey:(NSString *)key;// 子類重載方法,當屬性改變(也包括通過動畫造成的layer的改變)需要重繪layer的內(nèi)容時,返回YES。這個方法默認返回NO,不要通過CALayer返回YES,這樣會出現(xiàn)不定的錯誤。? ??
- (BOOL)shouldArchiveValueForKey:(NSString *)key;//在調(diào)用-encodeWithCode方法時使用,表示某一屬性值是否可以歸檔。默認YES,可以歸檔。子類中需要對自定義的屬性歸檔的話,可以調(diào)用這個方法? ? ----------瘸子、瞎子 ??
- (nullable instancetype)presentationLayer;//負責繪制? ?
?- (instancetype)modelLayer;//負責指路線? ??
----------層次設置,包括添加、插入、刪除、替換等----------? ??
- (void)addSublayer:(CALayer *)layer;? ?
- (void)insertSublayer:(CALayer *)layer atIndex:(unsigned)idx; ??
- (void)insertSublayer:(CALayer *)layer below:(nullable CALayer *)sibling; ??
- (void)insertSublayer:(CALayer *)layer above:(nullable CALayer *)sibling; ??
- (void)removeFromSuperlayer;? ??
- (void)replaceSublayer:(CALayer *)layer with:(CALayer *)layer2;? ??
---------位置、大小? ??
@property CGRect frame; ?//不支持動畫 ?
@property CGRect bounds; ?//支持動畫 ?
@property CGPoint position;//支持動畫? ?
@property CGFloat zPosition;//支持動畫? ?
@property CGPoint anchorPoint; //支持動畫?
@property CGFloat anchorPointZ; //支持動畫?
---------仿射變化? ? //用來訪問'變換'屬性:仿射變換的存取器方法。? ??
- (CGAffineTransform)affineTransform;? ??
- (void)setAffineTransform:(CGAffineTransform)m;? ??
@property CATransform3D transform;//3D位置? ??
--------邊角屬性? ??
@property(nullable, strong) CALayer *mask;//遮罩層layer,于layer重合的部分顯示 ?
@property BOOL masksToBounds;//是否遮擋裁邊外的部分? ??
@property CGFloat cornerRadius;//邊角半徑? ??
@property CGFloat borderWidth;//邊緣線寬度? ??
@property(nullable) CGColorRef borderColor;//邊緣線的顏色? ?
--------陰影屬性? ??
@property(nullable) CGColorRef shadowColor;//設置陰影顏色? ??
@property float shadowOpacity; //設置陰影透明度,默認0,值在[0,1]之間,支持動畫? ? @property CGSize shadowOffset;//設置陰影偏移量. 默認(0, -3),支持動畫.? ? @property CGFloat shadowRadius;//設置陰影圓角半徑? ??
@property(nullable) CGPathRef shadowPath;//設置陰影路徑.默認null,支持動畫.? ??
--------隱藏? ??
@property(getter=isDoubleSided) BOOL doubleSided;//當時false時,層遠離觀察者的那一面隱藏(圖層有雙面,是否都顯示,設置NO意思背面看不到,當為NO時,然后旋轉(zhuǎn)180度,則看不到layer層),默認是YES,支持動畫。? ??
--------坐標轉(zhuǎn)化? ??
- (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;? ??
-----------------命中檢測方法? ?
?//iOS中,hit-Testing的作用就是找出這個觸摸點下面的View(layer)是什么,HitTest會檢測這個點擊的點是不是發(fā)生在這個View(layer)上? ??
- (nullable CALayer *)hitTest:(CGPoint)p;//返回包含某一點的最上層的子layer? ??
- (BOOL)containsPoint:(CGPoint)p;//返回layer是否包含某一點? ??
-----------------內(nèi)容屬性? ??
@property(nullable, strong) id contents;//設置layer的內(nèi)容,一般會設置為CGImage的對象? ? ? ? ? //獲取內(nèi)容的rect尺寸? ??
@property CGRect contentsRect;? ? ? ? ??
*contentsGravity屬性決定了內(nèi)容對齊與填充方式,它可以分為兩個方面:? ?
?1.不改變內(nèi)容的原始大小? ??
這種模式中不會改變內(nèi)容的原始大小,如果層的尺寸小于內(nèi)容的尺寸,則內(nèi)容會被切割,如果層的尺寸大于內(nèi)容的尺寸,多出的部分將會顯示層的背景顏色。? ??
?2.改變內(nèi)容的尺寸大小? ?
?這種模式設置的實際上是一種填充方式:? ?
?*? ?
?@property(copy) NSString *contentsGravity;? ??
@property CGFloat contentsScale//設置內(nèi)容的縮放? ? ? ??
//這個屬性確定一個矩形區(qū)域,當內(nèi)容進行拉伸或者縮放的時候,這一部分的區(qū)域是會被形變的,例如默認設置為(0,0,1,1),則整個內(nèi)容區(qū)域都會參與形變。如果我們設置為(0.25,0.25,0.5,0.5),那么只有中間0.5*0.5比例寬高的區(qū)域會被拉伸,四周都不會。? ? @property CGRect contentsCenter;? ? ? ?
?//設置縮小的模式? ??
@property(copy) NSString *minificationFilter;? ? ? ??
//設置放大的模式 ? ?
@property(copy) NSString *magnificationFilter;? ? ? ??
//縮放因子? ? @property float minificationFilterBias;? ? ? ??
//設置內(nèi)容是否完全不透明。默認是NO? ??
@property(getter=isOpaque) BOOL opaque;? ? ? ??
//重新加載繪制內(nèi)容? ??
- (void)display;? ? ? ??
//設置內(nèi)容為需要重新繪制? ??
- (void)setNeedsDisplay;? ??
//設置某一區(qū)域內(nèi)容需要重新繪制? ??
- (void)setNeedsDisplayInRect:(CGRect)r;? ? ? ??
//獲取是否需要重新繪制? ??
- (BOOL)needsDisplay;? ? ? ??
//如果需要,進行內(nèi)容重繪? ??
- (void)displayIfNeeded;? ? ? ??
//這個屬性設置為YES,當內(nèi)容改變時會自動調(diào)用
- (void)setNeedsDisplay函數(shù).默認是NO? ??
@property BOOL needsDisplayOnBoundsChange;? ? ? ??
//默認是NO? ??
@property BOOL drawsAsynchronously? ? ? ??
//繪制與讀取內(nèi)容? ??
- (void)drawInContext:(CGContextRef)cox;? ??
- (void)renderInContext:(CGContextRef)cox;? ? ? ??
//這個屬性值用于限定層的邊緣是如何柵格化。通常,該屬性用于關(guān)閉抗鋸齒用于邊沿的其他緊靠層的邊緣,以消除否則會發(fā)生的接縫。默認值時所有值都抗鋸齒。? ??
@property CAEdgeAntialiasingMask edgeAntialiasingMask;? ? ? ?
?//當為真時,則層對由edgeAntialiasingMask屬性的值要求的邊抗鋸齒。默認值是從主束的Info.plist布爾UIViewEdgeAntialiasing屬性讀取。如果Info.plist中沒有找到值則,默認值是NO。? ??
@property BOOL allowsEdgeAntialiasing;? ? ? ??
//設置背景顏色 默認nil.? ??
@property(nullable) CGColorRef backgroundColor;? ? ? ??
//設置圓角半徑 默認zero? ??
@property CGFloat cornerRadius;? ? ? ??
//設置邊框?qū)挾? ??
@property CGFloat borderWidth;? ? ? ??
//設置邊框顏色? ??
@property(nullable) CGColorRef borderColor;? ? ? ??
//設置透明度? ??
@property float opacity;? ??
--------------------layer的關(guān)于動畫的方法? ? ? ??
//添加一個動畫對象 key值起到id的作用,通過key值,可以取到這個動畫對象? ??
- (void)addAnimation:(CAAnimation *)anim forKey:(nullable NSString *)key;? ? ? ??
//移除所有動畫對象? ??
- (void)removeAllAnimations;? ? ? ??
//移除某個動畫對象? ??
- (void)removeAnimationForKey:(NSString *)key;? ? ? ?
?//獲取所有動畫對象的key值? ??
- (nullable NSArray*)animationKeys;