CALayer.h
2016-09-25 本文已影响133人
ShenYj
#import <QuartzCore/CAMediaTiming.h>
#import <QuartzCore/CATransform3D.h>
#import <Foundation/NSObject.h>
@class NSArray, NSDictionary, NSEnumerator, CAAnimation, CALayerArray;
@protocol CAAction;
enum CAEdgeAntialiasingMask
{
kCALayerLeftEdge = 1U << 0, /* Minimum X edge. */
kCALayerRightEdge = 1U << 1, /* Maximum X edge. */
kCALayerBottomEdge = 1U << 2, /* Minimum Y edge. */
kCALayerTopEdge = 1U << 3, /* Maximum Y edge. */
};
@interface CALayer : NSObject <NSCoding, CAMediaTiming>
{
@private
struct _CALayerIvars {
int32_t refcount;
uint32_t magic;
void *layer;
#if TARGET_OS_MAC && !TARGET_RT_64_BIT
void *unused1[8];
#endif
} _attr;
}
+ (id)layer; // 图层
- (id)init; // 初始化
- (id)initWithLayer:(id)layer;
- (id)presentationLayer;
- (id)modelLayer;
+ (id)defaultValueForKey:(NSString *)key;
+ (BOOL)needsDisplayForKey:(NSString *)key;
- (BOOL)shouldArchiveValueForKey:(NSString *)key;
@property CGRect bounds; // 形状
@property CGPoint position; // 位置,(锚点所在的点)
@property CGFloat zPosition; // 在z轴的距离,通常用来显示不同图层的层位
@property CGPoint anchorPoint; // 锚点,形变的支点
@property CGFloat anchorPointZ; // z轴锚点
@property CATransform3D transform; // 3D形变属性
- (CGAffineTransform)affineTransform;
- (void)setAffineTransform:(CGAffineTransform)m;
@property CGRect frame;
@property(getter=isHidden) BOOL hidden;
@property(getter=isDoubleSided) BOOL doubleSided;
@property(getter=isGeometryFlipped) BOOL geometryFlipped;
- (BOOL)contentsAreFlipped;
@property(readonly) CALayer *superlayer;
- (void)removeFromSuperlayer;
@property(copy) NSArray *sublayers; // 所有子图层
- (void)addSublayer:(CALayer *)layer; // 添加图层
- (void)insertSublayer:(CALayer *)layer atIndex:(unsigned)idx; // 插入图层
- (void)insertSublayer:(CALayer *)layer below:(CALayer *)sibling;
- (void)insertSublayer:(CALayer *)layer above:(CALayer *)sibling;
- (void)replaceSublayer:(CALayer *)layer with:(CALayer *)layer2; // 替换图层
@property CATransform3D sublayerTransform;
@property(retain) CALayer *mask;
@property BOOL masksToBounds; // 超过范围的剪掉,看不见
- (CGPoint)convertPoint:(CGPoint)p fromLayer:(CALayer *)l;
- (CGPoint)convertPoint:(CGPoint)p toLayer:(CALayer *)l;
- (CGRect)convertRect:(CGRect)r fromLayer:(CALayer *)l;
- (CGRect)convertRect:(CGRect)r toLayer:(CALayer *)l;
- (CFTimeInterval)convertTime:(CFTimeInterval)t fromLayer:(CALayer *)l;
- (CFTimeInterval)convertTime:(CFTimeInterval)t toLayer:(CALayer *)l;
- (CALayer *)hitTest:(CGPoint)p;
- (BOOL)containsPoint:(CGPoint)p;
@property(retain) id contents; // 内容
@property CGRect contentsRect; // 内容所在的矩形框
@property(copy) NSString *contentsGravity; // 内容所在的位置 根据 左中右 和上中下划分成9个区域
@property CGFloat contentsScale;
@property CGRect contentsCenter;
@property(copy) NSString *minificationFilter, *magnificationFilter;
@property float minificationFilterBias;
@property(getter=isOpaque) BOOL opaque;
- (void)display;
- (void)setNeedsDisplay;
- (void)setNeedsDisplayInRect:(CGRect)r;
- (BOOL)needsDisplay;
- (void)displayIfNeeded;
@property BOOL needsDisplayOnBoundsChange;
@property BOOL drawsAsynchronously;
- (void)drawInContext:(CGContextRef)ctx;
- (void)renderInContext:(CGContextRef)ctx;
@property unsigned int edgeAntialiasingMask;
@property BOOL allowsEdgeAntialiasing;
@property CGColorRef backgroundColor;
@property CGFloat cornerRadius; // 圆角
@property CGFloat borderWidth; // 边框宽度
@property CGColorRef borderColor; //边框颜色
@property float opacity;
@property BOOL allowsGroupOpacity;
@property(retain) id compositingFilter;
@property(copy) NSArray *filters;
@property(copy) NSArray *backgroundFilters;
@property BOOL shouldRasterize;
@property CGFloat rasterizationScale;
@property CGColorRef shadowColor; // 阴影颜色
@property float shadowOpacity; // 阴影透明度
@property CGSize shadowOffset; // 阴影偏差
@property CGFloat shadowRadius; // 阴影向周围模糊的程度,0代表没有模糊
@property CGPathRef shadowPath; // 阴影路径
- (CGSize)preferredFrameSize; // 最适合的尺寸
- (void)setNeedsLayout; // 重新布局
- (BOOL)needsLayout; // 是否需要重新布局
- (void)layoutIfNeeded; // 需要时布局
- (void)layoutSublayers; // 重新布局子图层
+ (id<CAAction>)defaultActionForKey:(NSString *)event;
- (id<CAAction>)actionForKey:(NSString *)event;
@property(copy) NSDictionary *actions; // 图层的所有行为动画,这里可以修改隐式动画
- (void)addAnimation:(CAAnimation *)anim forKey:(NSString *)key; // 增加核心动画
- (void)removeAllAnimations; // 移除所有动画
- (void)removeAnimationForKey:(NSString *)key; // 移除某一个动画
- (NSArray *)animationKeys; // 动画的keys
- (CAAnimation *)animationForKey:(NSString *)key; // 某一个key的动画
@property(copy) NSString *name;
@property(assign) id delegate;
@property(copy) NSDictionary *style;
@end
#pragma - mark - 行为
@protocol CAAction
- (void)runActionForKey:(NSString *)event object:(id)anObject
arguments:(NSDictionary *)dict;
@end
#pragma - mark - 图层代理
@interface NSObject (CALayerDelegate)
- (void)displayLayer:(CALayer *)layer;
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx;
- (void)layoutSublayersOfLayer:(CALayer *)layer;
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event;
@end
CA_EXTERN NSString * const kCAGravityCenter
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityTop
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityBottom
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityLeft
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityRight
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityTopLeft
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityTopRight
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityBottomLeft
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityBottomRight
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityResize
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityResizeAspect
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAGravityResizeAspectFill
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAFilterNearest
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAFilterLinear
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAFilterTrilinear
__OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_3_0);
CA_EXTERN NSString * const kCAOnOrderIn
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCAOnOrderOut
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);
CA_EXTERN NSString * const kCATransition
__OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);