iOS UIKit框架学习—UIView 发表于 2017-01-12 | 分类于 iOS | | 阅读次数: UIView类定义了屏幕上一个矩形区域,在iOS中几乎所有的可视化控件都是UIView的子类,它还负责视图的内容管理、子视图管理、事件处理、动画实现等 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469@protocol UICoordinateSpace <NSObject>// 将当前的坐标空间点转换到指定的坐标空间- (CGPoint)convertPoint:(CGPoint)point toCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace NS_AVAILABLE_IOS(8_0);// 将指定的坐标空间点转换到当前的坐标空间- (CGPoint)convertPoint:(CGPoint)point fromCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace NS_AVAILABLE_IOS(8_0);// 将当前的矩形坐标空间转换到指定的矩形坐标空间- (CGRect)convertRect:(CGRect)rect toCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace NS_AVAILABLE_IOS(8_0);// 将指定的矩形坐标空间转换到当前的矩形坐标空间- (CGRect)convertRect:(CGRect)rect fromCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace NS_AVAILABLE_IOS(8_0);// 该view在本地坐标系统中的位置和大小(参照点是,本地坐标系统)@property (readonly, nonatomic) CGRect bounds NS_AVAILABLE_IOS(8_0);@end// 视图的基础图层#if UIKIT_DEFINE_AS_PROPERTIES@property(class, nonatomic, readonly) Class layerClass;#else+ (Class)layerClass;#endif// 初始化视图并设置位置和大小- (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;// 用于xib初始化- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;// 是否可以交互@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // default is YES.// 当前视图标签@property(nonatomic) NSInteger tag; // default is 0// 用于视图渲染的核心动画层@property(nonatomic,readonly,strong) CALayer *layer;#if UIKIT_DEFINE_AS_PROPERTIES// 视图是否可以被聚集(返回YES可能是:视图被隐藏、透明度为0,userInteractionEnabled设置为NO等)@property(nonatomic,readonly) BOOL canBecomeFocused NS_AVAILABLE_IOS(9_0); // NO by default#else- (BOOL)canBecomeFocused NS_AVAILABLE_IOS(9_0); // NO by default#endif// 当前项是否可以被聚焦@property (readonly, nonatomic, getter=isFocused) BOOL focused NS_AVAILABLE_IOS(9_0);// 左右滑动翻转效果@property (nonatomic) UISemanticContentAttribute semanticContentAttribute NS_AVAILABLE_IOS(9_0);// 返回界面的方向+ (UIUserInterfaceLayoutDirection)userInterfaceLayoutDirectionForSemanticContentAttribute:(UISemanticContentAttribute)attribute NS_AVAILABLE_IOS(9_0);// 返回相对于指定视图的界面方向+(UIUserInterfaceLayoutDirection)userInterfaceLayoutDirectionForSemanticContentAttribute:(UISemanticContentAttribute)semanticContentAttribute relativeToLayoutDirection:(UIUserInterfaceLayoutDirection)layoutDirection NS_AVAILABLE_IOS(10_0);// 安排即时内容的布局的方向@property (readonly, nonatomic) UIUserInterfaceLayoutDirection effectiveUserInterfaceLayoutDirection NS_AVAILABLE_IOS(10_0);@end@interface UIView(UIViewGeometry)// 父视图位置(参照点是,父view坐标系统)@property(nonatomic) CGRect frame;// 该view在本地坐标系统中的位置和大小(参照点是,本地坐标系统)@property(nonatomic) CGRect bounds;// frame中的中心点(决定当前视图是否是处理触摸事件的唯一对象)@property(nonatomic) CGPoint center;// 视图变换@property(nonatomic) CGAffineTransform transform;// 视图内容的缩放比例@property(nonatomic) CGFloat contentScaleFactor NS_AVAILABLE_IOS(4_0);// 支持多点触控@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled __TVOS_PROHIBITED; // default is NO// 决定当前视图是否处理出门事件的唯一对象@property(nonatomic,getter=isExclusiveTouch) BOOL exclusiveTouch __TVOS_PROHIBITED; // default is NO// 在指定点上点击测试指定事件- (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event;// 测试指定的点是否包含在接收对象中- (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event; // default returns YES if point is in bounds// 转换视图间坐标// 转换一个点从接受对象的坐标系到指定视图- (CGPoint)convertPoint:(CGPoint)point toView:(nullable UIView *)view;// 与上面相反,指定视图坐标中的一个点转换为接收对象- (CGPoint)convertPoint:(CGPoint)point fromView:(nullable UIView *)view;// 将当前的矩形坐标空间转换到指定的矩形坐标空间- (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;// 将指定的矩形坐标空间转换到当前的矩形坐标空间- (CGRect)convertRect:(CGRect)rect fromView:(nullable UIView *)view;// 自动尺寸调整@property(nonatomic) BOOL autoresizesSubviews; // default is YES. if set, subviews are adjusted according to their autoresizingMask if self.bounds changes// 自动调整子控件与父控件中间的位置,宽高@property(nonatomic) UIViewAutoresizing autoresizingMask;// 计算并返回的大小最适合它的子视图的视图。(让视图计算最适合子视图的大小,即能把全部子视图显示出来所需要的最小的size)- (CGSize)sizeThatFits:(CGSize)size;// 得到最适合当前包含它子视图的尺寸- (void)sizeToFit;@end@interface UIView(UIViewHierarchy)// 当前视图的父视图@property(nullable, nonatomic,readonly) UIView *superview;// 当前视图的所有子视图@property(nonatomic,readonly,copy) NSArray<__kindof UIView *> *subviews;// 当前视图上的UIWindow@property(nullable, nonatomic,readonly) UIWindow *window;// 从父视图中移除- (void)removeFromSuperview;// 在指定的位置插入子视图,视图的所有视图其实组成了一个数组- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;// 交换两子视图的位置- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;// 添加视图- (void)addSubview:(UIView *)view;// 将指定的子视图移动到指定siblingSubview子视图的后面- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;// 将指定的子视图移动到指定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:(nullable UIView *)newSuperview;// 通知视图已经移动到一个新的父视图中- (void)didMoveToSuperview;// 通知视图将要移动到一个新的window中- (void)willMoveToWindow:(nullable UIWindow *)newWindow;// 通知视图已经移动到一个新的window中- (void)didMoveToWindow;// 判断接收对象是否是指定视图的子视图,或与指定视图是同一视图- (BOOL)isDescendantOfView:(UIView *)view; // returns YES for self.// 返回指定标签匹配到的视图- (nullable __kindof UIView *)viewWithTag:(NSInteger)tag; // recursive search. includes self// 标记为需要重新布局,异步调用layoutIfNeeded刷新布局,不立即刷新,但layoutSubviews一定会被调用- (void)setNeedsLayout;// 如果有需要刷新的标记,立即调用layoutSubviews进行布局(如果没有标记,不会调用layoutSubviews)- (void)layoutIfNeeded;// 将子类重新布局- (void)layoutSubviews;// 设置视图的间距@property (nonatomic) UIEdgeInsets layoutMargins NS_AVAILABLE_IOS(8_0);// 是否将当前视图的间距和父视图相同@property (nonatomic) BOOL preservesSuperviewLayoutMargins NS_AVAILABLE_IOS(8_0); // default is NO// 通知布局发生变化- (void)layoutMarginsDidChange NS_AVAILABLE_IOS(8_0);// 视图间距引导@property(readonly,strong) UILayoutGuide *layoutMarginsGuide NS_AVAILABLE_IOS(9_0);/// 获取此区域的内的布局引导@property (nonatomic, readonly, strong) UILayoutGuide *readableContentGuide NS_AVAILABLE_IOS(9_0);@end@interface UIView(UIViewRendering)// 在指定的区域绘画视图- (void)drawRect:(CGRect)rect;// 标记整个视图的边界矩形需要重绘- (void)setNeedsDisplay;// 标记在指定区域内的视图的边界需要重绘- (void)setNeedsDisplayInRect:(CGRect)rect;// 决定子视图是否被限定在当前视图的bounds中@property(nonatomic) BOOL clipsToBounds; //Default is NO.// 背景色@property(nullable, nonatomic,copy) UIColor *backgroundColor UI_APPEARANCE_SELECTOR;// 透明度@property(nonatomic) CGFloat alpha; // animatable. default is 1.0// 不透明度@property(nonatomic,getter=isOpaque) BOOL opaque; // default is YES.// 决定在视图重画之前是否先清理视图以前的内容@property(nonatomic) BOOL clearsContextBeforeDrawing; // default is YES.// 是否隐藏视图@property(nonatomic,getter=isHidden) BOOL hidden; // default is NO.// 视图内容风格@property(nonatomic) UIViewContentMode contentMode; // default is UIViewContentModeScaleToFill// 一个可选视图,用于屏蔽视图内容@property(nullable, nonatomic,strong) UIView *maskView NS_AVAILABLE_IOS(8_0);// 最底部视图色彩@property(null_resettable, nonatomic, strong) UIColor *tintColor NS_AVAILABLE_IOS(7_0);// 色彩调整风格@property(nonatomic) UIViewTintAdjustmentMode tintAdjustmentMode NS_AVAILABLE_IOS(7_0);// 告诉系统tintColor值将会改变- (void)tintColorDidChange NS_AVAILABLE_IOS(7_0);@end@interface UIView(UIViewAnimation)// 标记开始/提交动画块的开始+ (void)beginAnimations:(nullable NSString *)animationID context:(nullable void *)context;// 标记开始/提交动画块的结束,并为执行调度动画+ (void)commitAnimations;// 设置动画消息的委托+ (void)setAnimationDelegate:(nullable id)delegate; // default = nil// 设置动画启动时发送给动画委托的消息+ (void)setAnimationWillStartSelector:(nullable SEL)selector; // default = NULL. -animationWillStart:(NSString *)animationID context:(void *)context// 设置动画停止时发送给动画委托的消息+ (void)setAnimationDidStopSelector:(nullable SEL)selector; // default = NULL. -animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context// 设置动画持续时间+ (void)setAnimationDuration:(NSTimeInterval)duration; // default = 0.2// 设置动画延迟执行时间+ (void)setAnimationDelay:(NSTimeInterval)delay; // default = 0.0// 设置动画开始时间+ (void)setAnimationStartDate:(NSDate *)startDate; // default = now ([NSDate date])// 设置动画曲线+ (void)setAnimationCurve:(UIViewAnimationCurve)curve; // default = UIViewAnimationCurveEaseInOut// 设置动画重复次数+ (void)setAnimationRepeatCount:(float)repeatCount; // default = 0.0.// 设置动画是否反转执行+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses; // default = NO.// 设置动画是否从当前状态开始播放+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState; // default = NO.// 设置到指定视图的过渡动画+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache;// 设置是否启用了动画+ (void)setAnimationsEnabled:(BOOL)enabled;// 是否启用了动画#if UIKIT_DEFINE_AS_PROPERTIES@property(class, nonatomic, readonly) BOOL areAnimationsEnabled;#else+ (BOOL)areAnimationsEnabled;#endif// 禁用视图的过渡动画+ (void)performWithoutAnimation:(void (NS_NOESCAPE ^)(void))actionsWithoutAnimation NS_AVAILABLE_IOS(7_0);// 当前动画的持续时间#if UIKIT_DEFINE_AS_PROPERTIES@property(class, nonatomic, readonly) NSTimeInterval inheritedAnimationDuration NS_AVAILABLE_IOS(9_0);#else+ (NSTimeInterval)inheritedAnimationDuration NS_AVAILABLE_IOS(9_0);#endif@end@interface UIView(UIViewAnimationWithBlocks)// 用于对一个或多个视图的改变的持续时间、延时、选项动画完成时的操作+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);// 用于对一个或多个视图的改变的持续时间、选项动画完成时的操作+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(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)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);// 为指定的容器视图创建转换动画+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);// 使用给定的参数在指定视图之间创建转换动画+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);// 在一个或多个视图上执行指定的系统提供的动画,以及定义的可选并行动画.+ (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray<__kindof UIView *> *)views options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))parallelAnimations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);@end@interface UIView (UIViewKeyframeAnimations)// 创建一个动画块对象,可用于为当前视图设置基于关键帧的动画+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);// 添加指定开始时间、持续时间的关键帧动画+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTime relativeDuration:(double)frameDuration animations:(void (^)(void))animations NS_AVAILABLE_IOS(7_0);@end@interface UIView (UIViewGestureRecognizers)// 当前视图所附加的手势识别器@property(nullable, nonatomic,copy) NSArray<__kindof UIGestureRecognizer *> *gestureRecognizers NS_AVAILABLE_IOS(3_2);// 为视图添加一个手势识别器- (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer NS_AVAILABLE_IOS(3_2);// 删除视图上的一个手势识别器- (void)removeGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer NS_AVAILABLE_IOS(3_2);// 开始一个手势识别器- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer NS_AVAILABLE_IOS(6_0);@end@interface UIView (UIViewMotionEffects)// 开始向视图中添加运动效果- (void)addMotionEffect:(UIMotionEffect *)effect NS_AVAILABLE_IOS(7_0);// 删除视图中的运动效果- (void)removeMotionEffect:(UIMotionEffect *)effect NS_AVAILABLE_IOS(7_0);// 视图中运动效果的数组@property (copy, nonatomic) NSArray<__kindof UIMotionEffect *> *motionEffects NS_AVAILABLE_IOS(7_0);@end@interface UIView (UIConstraintBasedLayoutInstallingConstraints)// 视图所持有的约束@property(nonatomic,readonly) NSArray<__kindof NSLayoutConstraint *> *constraints NS_AVAILABLE_IOS(6_0);// 添加一个约束- (void)addConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0);// 添加多个约束- (void)addConstraints:(NSArray<__kindof NSLayoutConstraint *> *)constraints NS_AVAILABLE_IOS(6_0);// 移除视图上指定的约束- (void)removeConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0);// 移除指定的一组约束- (void)removeConstraints:(NSArray<__kindof NSLayoutConstraint *> *)constraints NS_AVAILABLE_IOS(6_0);@end@interface UIView (UIConstraintBasedLayoutCoreMethods)// 更新视图和其子视图的约束- (void)updateConstraintsIfNeeded NS_AVAILABLE_IOS(6_0);// 为视图更新约束- (void)updateConstraints NS_AVAILABLE_IOS(6_0) NS_REQUIRES_SUPER;// 视图的约束是否需要更新- (BOOL)needsUpdateConstraints NS_AVAILABLE_IOS(6_0);// 设置视图的约束需要更新- (void)setNeedsUpdateConstraints NS_AVAILABLE_IOS(6_0);@end@interface UIView (UIConstraintBasedCompatibility)// 是否自动尺寸转换为自动布局@property(nonatomic) BOOL translatesAutoresizingMaskIntoConstraints NS_AVAILABLE_IOS(6_0); // Default YES// 视图是否一来与基础自动布局的约束#if UIKIT_DEFINE_AS_PROPERTIES@property(class, nonatomic, readonly) BOOL requiresConstraintBasedLayout NS_AVAILABLE_IOS(6_0);#else+ (BOOL)requiresConstraintBasedLayout NS_AVAILABLE_IOS(6_0);#endif@end@interface UIView (UIConstraintBasedLayoutLayering)// 返回给定框架的视图的对齐矩阵- (CGRect)alignmentRectForFrame:(CGRect)frame NS_AVAILABLE_IOS(6_0);// 返回给定对齐矩形的视图的frame- (CGRect)frameForAlignmentRect:(CGRect)alignmentRect NS_AVAILABLE_IOS(6_0);// 返回从视图的frame上定义的对齐矩阵的边框#if UIKIT_DEFINE_AS_PROPERTIES@property(nonatomic, readonly) UIEdgeInsets alignmentRectInsets NS_AVAILABLE_IOS(6_0);#else- (UIEdgeInsets)alignmentRectInsets NS_AVAILABLE_IOS(6_0);#endif// 返回满足基线约束条件的视图- (UIView *)viewForBaselineLayout NS_DEPRECATED_IOS(6_0, 9_0, "Override -viewForFirstBaselineLayout or -viewForLastBaselineLayout as appropriate, instead") __TVOS_PROHIBITED;// 返回用于满足第一基线约束的视图@property(readonly,strong) UIView *viewForFirstBaselineLayout NS_AVAILABLE_IOS(9_0);// 返回用于满足上次基线约束的视图@property(readonly,strong) UIView *viewForLastBaselineLayout NS_AVAILABLE_IOS(9_0);UIKIT_EXTERN const CGFloat UIViewNoIntrinsicMetric NS_AVAILABLE_IOS(6_0); // -1// 返回接收对象的原本大小#if UIKIT_DEFINE_AS_PROPERTIES@property(nonatomic, readonly) CGSize intrinsicContentSize NS_AVAILABLE_IOS(6_0);#else- (CGSize)intrinsicContentSize NS_AVAILABLE_IOS(6_0);#endif// 废除视图原本内容的size- (void)invalidateIntrinsicContentSize NS_AVAILABLE_IOS(6_0);// 设置当视图要变大时,视图的压缩改变方式,返回一个优先权(确定view有多大的优先级阻止自己变大)- (UILayoutPriority)contentHuggingPriorityForAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0);// 设置放先权- (void)setContentHuggingPriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0);// 设置当视图要变小时,视图的压缩改变方式,是水平缩小还是垂直缩小,并返回一个优先权(确定有多大的优先级阻止自己变小)- (UILayoutPriority)contentCompressionResistancePriorityForAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0);// 设置优先权- (void)setContentCompressionResistancePriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0);@end// Size To FitUIKIT_EXTERN const CGSize UILayoutFittingCompressedSize NS_AVAILABLE_IOS(6_0);UIKIT_EXTERN const CGSize UILayoutFittingExpandedSize NS_AVAILABLE_IOS(6_0);@interface UIView (UIConstraintBasedLayoutFittingSize)// 返回满足持有约束的视图的size- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize NS_AVAILABLE_IOS(6_0);// 返回满足它所包含的约束的视图的大小- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority NS_AVAILABLE_IOS(8_0);@end@interface UIView (UILayoutGuideSupport)// 此视图拥有布局向导对象的数组@property(nonatomic,readonly,copy) NSArray<__kindof UILayoutGuide *> *layoutGuides NS_AVAILABLE_IOS(9_0);// 向视图中添加布局向导- (void)addLayoutGuide:(UILayoutGuide *)layoutGuide NS_AVAILABLE_IOS(9_0);// 移除视图中的布局向导- (void)removeLayoutGuide:(UILayoutGuide *)layoutGuide NS_AVAILABLE_IOS(9_0);@end@class NSLayoutXAxisAnchor,NSLayoutYAxisAnchor,NSLayoutDimension;@interface UIView (UIViewLayoutConstraintCreation)// 布局视图的前缘框的布局锚点@property(readonly, strong) NSLayoutXAxisAnchor *leadingAnchor NS_AVAILABLE_IOS(9_0);// 布局视图的后缘边框的布局锚点@property(readonly, strong) NSLayoutXAxisAnchor *trailingAnchor NS_AVAILABLE_IOS(9_0);// 布局视图的左边框的布局锚点@property(readonly, strong) NSLayoutXAxisAnchor *leftAnchor NS_AVAILABLE_IOS(9_0);// 布局视图的右边框的布局锚点@property(readonly, strong) NSLayoutXAxisAnchor *rightAnchor NS_AVAILABLE_IOS(9_0);// 布局视图的顶边框的布局锚点@property(readonly, strong) NSLayoutYAxisAnchor *topAnchor NS_AVAILABLE_IOS(9_0);// 布局视图的底边框的布局锚点@property(readonly, strong) NSLayoutYAxisAnchor *bottomAnchor NS_AVAILABLE_IOS(9_0);// 布局视图的宽度@property(readonly, strong) NSLayoutDimension *widthAnchor NS_AVAILABLE_IOS(9_0);// 布局视图的高度@property(readonly, strong) NSLayoutDimension *heightAnchor NS_AVAILABLE_IOS(9_0);// 布局视图的水平中心轴@property(readonly, strong) NSLayoutXAxisAnchor *centerXAnchor NS_AVAILABLE_IOS(9_0);// 布局视图的垂直中心轴@property(readonly, strong) NSLayoutYAxisAnchor *centerYAnchor NS_AVAILABLE_IOS(9_0);// 一个代表对视图中的文本的最高线基线布置锚@property(readonly, strong) NSLayoutYAxisAnchor *firstBaselineAnchor NS_AVAILABLE_IOS(9_0);// 一个代表对视图中的文本的最低线基线布置锚@property(readonly, strong) NSLayoutYAxisAnchor *lastBaselineAnchor NS_AVAILABLE_IOS(9_0);@end@interface UIView (UIConstraintBasedLayoutDebugging)// 返回影响一个给定轴视图布局的约束- (NSArray<__kindof NSLayoutConstraint *> *)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0);// 视图的位置是否不完全指定#if UIKIT_DEFINE_AS_PROPERTIES@property(nonatomic, readonly) BOOL hasAmbiguousLayout NS_AVAILABLE_IOS(6_0);#else- (BOOL)hasAmbiguousLayout NS_AVAILABLE_IOS(6_0);#endif// 在不同的有效值之间用一个模糊的布局随机改变视图的frame- (void)exerciseAmbiguityInLayout NS_AVAILABLE_IOS(6_0);@end@interface UILayoutGuide (UIConstraintBasedLayoutDebugging)// 返回对给定轴影响视图布局的约束- (NSArray<__kindof NSLayoutConstraint *> *)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(10_0);// 确定影响视图布局的约束是否完全指定视图的位置#if UIKIT_DEFINE_AS_PROPERTIES@property(nonatomic, readonly) BOOL hasAmbiguousLayout NS_AVAILABLE_IOS(10_0);#else- (BOOL)hasAmbiguousLayout NS_AVAILABLE_IOS(10_0);#endif@end@interface UIView (UIStateRestoration)// 该标示符决定该视图是否支持恢复状态@property (nullable, nonatomic, copy) NSString *restorationIdentifier NS_AVAILABLE_IOS(6_0);// 编码视图的状态信息- (void) encodeRestorableStateWithCoder:(NSCoder *)coder NS_AVAILABLE_IOS(6_0);// 解码一个视图状态信息- (void) decodeRestorableStateWithCoder:(NSCoder *)coder NS_AVAILABLE_IOS(6_0);@end@interface UIView (UISnapshotting)// 根据当前视图的内容返回快照视图- (nullable UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates NS_AVAILABLE_IOS(7_0);// 返回一个基于当前视图指定内容的快照视图,可插入- (nullable UIView *)resizableSnapshotViewFromRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates withCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(7_0);// 呈现一个快照的完整视图层次可见屏幕为当前上下文- (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates NS_AVAILABLE_IOS(7_0);@end 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114// 动画效果typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {UIViewAnimationCurveEaseInOut, // 淡入淡出UIViewAnimationCurveEaseIn, // 淡入UIViewAnimationCurveEaseOut, // 淡出UIViewAnimationCurveLinear,};// 视图内容风格typedef NS_ENUM(NSInteger, UIViewContentMode) {UIViewContentModeScaleToFill, // 缩放内容到合适比例大小UIViewContentModeScaleAspectFit, // 缩放内容到合适的大小,边界多余部分透明UIViewContentModeScaleAspectFill, // 缩放内容填充到指定大小,边界多余的部分省略.UIViewContentModeRedraw, // 重绘视图边界 (需调用 -setNeedsDisplay)UIViewContentModeCenter, // 视图保持等比缩放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 // 调整视图底部间距};// 动画选项typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {UIViewAnimationOptionLayoutSubviews = 1 << 0, // 子视图在指定的时间内完成在父视图上的自动UIViewAnimationOptionAllowUserInteraction = 1 << 1, // 开启交互动画UIViewAnimationOptionBeginFromCurrentState = 1 << 2, // 从当前值开始动画UIViewAnimationOptionRepeat = 1 << 3, // 无限重复UIViewAnimationOptionAutoreverse = 1 << 4, // 自动来回UIViewAnimationOptionOverrideInheritedDuration = 1 << 5, // 忽略嵌套的动画的时间UIViewAnimationOptionOverrideInheritedCurve = 1 << 6, // 忽略嵌套的路径动画UIViewAnimationOptionAllowAnimatedContent = 1 << 7, // 只执行过渡动画UIViewAnimationOptionShowHideTransitionViews = 1 << 8, // 隐藏或展示过渡动画视图UIViewAnimationOptionOverrideInheritedOptions = 1 << 9, // 不继承任何动画类型// 同上UIViewAnimationOptionCurveEaseInOut = 0 << 16, // defaultUIViewAnimationOptionCurveEaseIn = 1 << 16,UIViewAnimationOptionCurveEaseOut = 2 << 16,UIViewAnimationOptionCurveLinear = 3 << 16,UIViewAnimationOptionTransitionNone = 0 << 20, // defaultUIViewAnimationOptionTransitionFlipFromLeft = 1 << 20,UIViewAnimationOptionTransitionFlipFromRight = 2 << 20,UIViewAnimationOptionTransitionCurlUp = 3 << 20,UIViewAnimationOptionTransitionCurlDown = 4 << 20,UIViewAnimationOptionTransitionCrossDissolve = 5 << 20,UIViewAnimationOptionTransitionFlipFromTop = 6 << 20,UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20,} NS_ENUM_AVAILABLE_IOS(4_0);// 关键帧动画typedef NS_OPTIONS(NSUInteger, UIViewKeyframeAnimationOptions) {UIViewKeyframeAnimationOptionLayoutSubviews = UIViewAnimationOptionLayoutSubviews, // 子视图在指定的时间内完成在父视图上的自动布局的动画UIViewKeyframeAnimationOptionAllowUserInteraction = UIViewAnimationOptionAllowUserInteraction, // 开启交互动画UIViewKeyframeAnimationOptionBeginFromCurrentState = UIViewAnimationOptionBeginFromCurrentState, // 从当前值开始动画UIViewKeyframeAnimationOptionRepeat = UIViewAnimationOptionRepeat, // 无限重复UIViewKeyframeAnimationOptionAutoreverse = UIViewAnimationOptionAutoreverse, // 自动来回UIViewKeyframeAnimationOptionOverrideInheritedDuration = UIViewAnimationOptionOverrideInheritedDuration, // 忽略嵌套的动画的时间UIViewKeyframeAnimationOptionOverrideInheritedOptions = UIViewAnimationOptionOverrideInheritedOptions, // 不继承任何动画类型UIViewKeyframeAnimationOptionCalculationModeLinear = 0 << 10, // defaultUIViewKeyframeAnimationOptionCalculationModeDiscrete = 1 << 10,UIViewKeyframeAnimationOptionCalculationModePaced = 2 << 10,UIViewKeyframeAnimationOptionCalculationModeCubic = 3 << 10,UIViewKeyframeAnimationOptionCalculationModeCubicPaced = 4 << 10} NS_ENUM_AVAILABLE_IOS(7_0);typedef NS_ENUM(NSUInteger, UISystemAnimation) {UISystemAnimationDelete, // 完成时从视图中删除} NS_ENUM_AVAILABLE_IOS(7_0);// 色彩调整风格typedef NS_ENUM(NSInteger, UIViewTintAdjustmentMode) {UIViewTintAdjustmentModeAutomatic, // 与父视图相同UIViewTintAdjustmentModeNormal, // 未经修改的UIViewTintAdjustmentModeDimmed, // 饱和、暗淡的原始色} NS_ENUM_AVAILABLE_IOS(7_0);// 左右切换或左右布局typedef NS_ENUM(NSInteger, UISemanticContentAttribute) {UISemanticContentAttributeUnspecified = 0, // 左右切换时视图翻转UISemanticContentAttributePlayback, // 音乐播放按钮设置,左右切换此视图不会翻转UISemanticContentAttributeSpatial, // 控件方向不能改变UISemanticContentAttributeForceLeftToRight, // 从左到右布局UISemanticContentAttributeForceRightToLeft // 从右到左布局} NS_ENUM_AVAILABLE_IOS(9_0);// 约束布局中心线类型typedef NS_ENUM(NSInteger, UILayoutConstraintAxis) {UILayoutConstraintAxisHorizontal = 0, // 以水平线为中心UILayoutConstraintAxisVertical = 1 // 以垂直线为中心};