#import <Foundation/Foundation.h> 基础框架入口
#import <UIKit/UIResponder.h>触摸事件响应处理
#import <UIKit/UIInterface.h> 界面UIcolor, UIFont 定义
#import <UIKit/UIKitDefines.h> 一些宏定义
#import <UIKit/UIAppearance.h> 外观代理
#import <UIKit/NSLayoutConstraint.h> 布局对象约束
typedef NS_ENUM(NSInteger, UIViewAnimationCurve) { //动画曲线
UIViewAnimationCurveEaseInOut, // slow at beginning and end 缓慢开始,中间加速,然后减速到结束
UIViewAnimationCurveEaseIn, // slow at beginning 缓慢开始,加速到结束
UIViewAnimationCurveEaseOut, // slow at end 加速开始,加速到结束
UIViewAnimationCurveLinear //正常速度
};
typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleToFill, 缩放内容到合适比例大小
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent 缩放内容到合适的大小,边界多余部分透明
UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped.缩放内容填充到指定大小,边界多余的部分省略
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay) 重绘视图边界
UIViewContentModeCenter, // contents remain same size. positioned adjusted. 视图保持等比缩放
UIViewContentModeTop, 视图顶部对齐
UIViewContentModeBottom, 视图底部对齐
UIViewContentModeLeft, 视图左侧对齐
UIViewContentModeRight, 视图右侧对齐
UIViewContentModeTopLeft, 视图左上角对齐
UIViewContentModeTopRight, 视图右上角对齐
UIViewContentModeBottomLeft, 视图左下角对齐
UIViewContentModeBottomRight, 视图右下角对齐
};
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
UIViewAnimationTransitionNone, 没有过渡
UIViewAnimationTransitionFlipFromLeft, 翻转视图从左到右
UIViewAnimationTransitionFlipFromRight, 翻转视图从右到左
UIViewAnimationTransitionCurlUp, 从上卷动
UIViewAnimationTransitionCurlDown, 从下卷动
};
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
UIViewAutoresizingNone = 0, 父视图变化,自己不变化
UIViewAutoresizingFlexibleLeftMargin = 1 << 0, 视图的左边界和父视图的宽度等比例变化
UIViewAutoresizingFlexibleWidth = 1 << 1,视图的宽度和父视图的宽度成比例变化
UIViewAutoresizingFlexibleRightMargin = 1 << 2, 视图的右边界和父视图的宽度等比例变化
UIViewAutoresizingFlexibleTopMargin = 1 << 3, 视图的上边界和父视图的高度成等比例变化
UIViewAutoresizingFlexibleHeight = 1 << 4, 视图的高度和父视图的高度成比例变化
UIViewAutoresizingFlexibleBottomMargin = 1 << 5 视图的下边界和父视图的高度成等比例变化
};
+ (Class)layerClass; // default is [CALayer class]. Used when creating the underlying layer for the view. 绘图布局
- (id)initWithFrame:(CGRect)frame; // 初始化视图布局
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // 确定是否接受用户事件
@property(nonatomic) NSInteger tag; // default is 0 标记视图对象
@property(nonatomic,readonly,retain) CALayer *layer; // 返回一个只读的视图层
@end
@interface UIView(UIViewGeometry)
@property(nonatomic) CGRect frame; 描述view在其父view坐标系中的定位和大小
@property(nonatomic) CGRect bounds; // 描述view自身的本地坐标系统的定位和大小
@property(nonatomic) CGPoint center; // 描述view的frame属性的中心点
@property(nonatomic) CGAffineTransform transform; // 描述view相对bounds的平移量
@property(nonatomic) CGFloat contentScaleFactor NS_AVAILABLE_IOS(4_0); 改变视图比例,主要用于修改分辨率,来支持高,低分辨率转化绘图
@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled; // default is NO 设置是否接受多点触摸。YES 是接受多点,NO 接受单点。
@property(nonatomic,getter=isExclusiveTouch) BOOL exclusiveTouch; // default is NO 当前视图独占触摸事件
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event; // 接收视图触摸事件,遍历视图,确定最终接受视图层
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event; // 判断触摸事件是否在当前视图
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view; 转化当前视图的坐标相对于另外一个视图的坐标
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view; 转化另外视图坐标相对于当前视图的坐标
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view; 转化当前视图的矩形坐标相对于另外一个视图的矩形
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;转化另外视图的矩形坐标相对于当前视图矩形
@property(nonatomic) BOOL autoresizesSubviews; // 判断是否接收边界的改变,YES:接收 NO:不接收
@property(nonatomic) UIViewAutoresizing autoresizingMask; // 视图边界大小调整参数
- (CGSize)sizeThatFits:(CGSize)size; // r 计算并返回一个最适应接收子视图的大小
- (void)sizeToFit; // 移动并调整子视图的大小
@end
@interface UIView(UIViewHierarchy)
@property(nonatomic,readonly) UIView *superview; 父视图
@property(nonatomic,readonly,copy) NSArray *subviews; 子视图
@property(nonatomic,readonly) UIWindow *window; 窗口
- (void)removeFromSuperview; 将当前视图从父视图和窗口移除,并且把它的响应事件的响应链移除。
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; 指定索引插入视图
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2; 指定索引交换子视图
视图的添加都是以栈的方式,即后进先出。
- (void)addSubview:(UIView *)view; 添加视图到最后- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;添加视图到底层
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview; 添加视图到顶层
- (void)bringSubviewToFront:(UIView *)view; 将指定子视图推送到前台(顶层)
- (void)sendSubviewToBack:(UIView *)view; 将指定子视图推送到后台
- (void)didAddSubview:(UIView *)subview;通知某个子视图已经添加
- (void)willRemoveSubview:(UIView *)subview;通知视图某个子视图即将移除
- (void)willMoveToSuperview:(UIView *)newSuperview; 通知即将移动到新的父视图中
- (void)didMoveToSuperview;通知已经到新父视图
- (void)willMoveToWindow:(UIWindow *)newWindow; 通知即将已移动到新的窗口
- (void)didMoveToWindow; 通知已经移动新的窗口
- (BOOL)isDescendantOfView:(UIView *)view; // returns YES for self. 判断一个视图是否在父视图层中
- (UIView *)viewWithTag:(NSInteger)tag; // recursive search. includes self 获取标记的子视图
// Allows you to perform layout before the drawing cycle happens. -layoutIfNeeded forces layout early
- (void)setNeedsLayout; 标记为需要重新布局,异步调用layoutIfNeeded刷新布局,不立即刷新,但layoutSubviews一定会被调用
- (void)layoutIfNeeded;如果,有需要刷新的标记,立即调用layoutSubviews进行布局(如果没有标记,不会调用layoutSubviews)
- (void)layoutSubviews; // override point. called by layoutIfNeeded automatically. As of iOS 6.0, when constraints-based layout is used the base implementation applies the constraints-based layout, otherwise it does nothing. 重新布局
@end
@interface UIView(UIViewAnimationWithBlocks)
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); 动画效果处理块
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0 动画效果处理块,无延迟
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL 动画效果处理块。无延迟,简单版
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); 过渡动画处理块
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // toView added to fromView.superview, fromView removed from its superview 视图之间切换过渡动画处理块
@end
@interface UIView(UIViewAnimationWithBlocks)
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); 动画效果处理块
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0 动画效果处理块,无延迟
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL 动画效果处理块。无延迟,简单版
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); 过渡动画处理块
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // toView added to fromView.superview, fromView removed from its superview 视图之间切换过渡动画处理块
@end@interface UIView(UIViewRendering)
- (void)drawRect:(CGRect)rect; 子类重写方法,重绘
- (void)setNeedsDisplay; 标记为需要重绘,异步调用drawRect
- (void)setNeedsDisplayInRect:(CGRect)rect; 标记为需要局部重绘
@property(nonatomic) BOOL clipsToBounds; // When YES, content and subviews are clipped to the bounds of the view. Default is NO. 决定子视图边界是否可以超过父视图范围
@property(nonatomic,copy) UIColor *backgroundColor; // default is nil 背景颜色
@property(nonatomic) CGFloat alpha; // animatable. default is 1.0 透明度, 取值范围为0.0 --- 1.0
@property(nonatomic,getter=isOpaque) BOOL opaque; // default is YES. opaque views must fill their entire bounds or the results are undefined. the active CGContext in drawRect: will not have been cleared and may have non-zeroed pixels 决定该消息接收者(UIView instance)是否让其视图不透明,用处在于给绘图系统提供一个性能优化开关。
@property(nonatomic) BOOL clearsContextBeforeDrawing; // default is YES. ignored for opaque views. for non-opaque views causes the active CGContext in drawRect: to be pre-filled with transparent pixels 决定绘制前是否清屏,默认为YES
@property(nonatomic,getter=isHidden) BOOL hidden; // default is NO. doesn't check superviews 视图是否隐藏,默认为NO(显示),YES为隐藏
@property(nonatomic) UIViewContentMode contentMode; // default is UIViewContentModeScaleToFill 视图边界填充
@property(nonatomic) CGRect contentStretch NS_DEPRECATED_IOS(3_0,6_0); // animatable. default is unit rectangle {{0,0} {1,1}}. Now deprecated: please use -[UIImage resizableImageWithCapInsets:] to achieve the same effect. 视图拉伸和缩略
@end