UIView

枚举

UIViewAnimationCurve

/** 支持的动画曲线。 */
typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {
    /** 缓入缓出曲线(动画缓慢开始,在其持续时间的中间加速,然后在完成之前再次减速),这是大多数动画的默认曲线。 */
    UIViewAnimationCurveEaseInOut,
    /** 缓入曲线(动画缓慢开始,然后随着进展而加速) */
    UIViewAnimationCurveEaseIn,
    /** 缓出曲线(动画快速开始,然后在完成时减慢速度) */
    UIViewAnimationCurveEaseOut,
    /** 线性动画曲线使动画在其持续时间内均匀发生。 */
    UIViewAnimationCurveLinear,
};

UIViewContentMode

/** 用于指定视图在其大小更改时如何调整其内容的选项。 */
typedef NS_ENUM(NSInteger, UIViewContentMode) {
    /** 如有必要,可以通过更改内容的宽高比来缩放内容以适合自身大小的选项。 */
    UIViewContentModeScaleToFill,
    /** 通过保持纵横比来缩放内容以适合视图大小的选项。 视图边界的任何剩余区域都是透明的。 */
    UIViewContentModeScaleAspectFit,
    /** 缩放内容以填充视图大小的选项。 可以剪裁内容的某些部分以填充视图的边界。 */
    UIViewContentModeScaleAspectFill,
    /** 通过调用setNeedsDisplay方法更改边界时重新显示视图的选项。 */
    UIViewContentModeRedraw,
    /** 将内容置于视图边界中心的选项,保持比例相同。 */
    UIViewContentModeCenter,
    /** 将内容对齐在视图边界顶部的选项。 */
    UIViewContentModeTop,
    /** 在视图边界中居中对齐底部内容的选项。 */
    UIViewContentModeBottom,
    /** 用于对齐视图左侧内容的选项。 */
    UIViewContentModeLeft,
    /** 用于对齐视图右侧内容的选项。 */
    UIViewContentModeRight,
    /** 用于对齐视图左上角内容的选项。 */
    UIViewContentModeTopLeft,
    /** 用于对齐视图右上角内容的选项。 */
    UIViewContentModeTopRight,
    /** 用于对齐视图左下角内容的选项。 */
    UIViewContentModeBottomLeft,
    /** 用于对齐视图左下角内容的选项。 */
    UIViewContentModeBottomRight,
};

UIViewAnimationTransition

/** 用于动画块对象的动画转换选项。 */
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
    /** 用于指示未指定转换的选项。 */
    UIViewAnimationTransitionNone,
    /** 从左到右翻转垂直轴视图的过渡。 视图的左侧朝向后和右侧朝向前移动。 */
    UIViewAnimationTransitionFlipFromLeft,
    /** 从左到右翻转垂直轴视图的过渡。 视图的左侧朝向前和右侧朝向后移动。 */
    UIViewAnimationTransitionFlipFromRight,
    /** 从底部向上卷曲视图的过渡。 */
    UIViewAnimationTransitionCurlUp,
    /** 从顶部向下卷曲视图的过渡。 */
    UIViewAnimationTransitionCurlDown,
};

UIViewAnimationTransition

/** 自动视图调整大小的选项。 */
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
};

UIViewAnimationOptions

/** 使用块对象动画视图的选项。 */
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,
    /** 缓入曲线使动画开始缓慢,然后随着进展而加速。 */
    UIViewAnimationOptionCurveEaseIn               = 1 << 16,
    /** 缓出曲线会使动画快速开始,然后在完成时变慢。 */
    UIViewAnimationOptionCurveEaseOut              = 2 << 16,
    /** 线性动画曲线使动画在其持续时间内均匀发生。 */
    UIViewAnimationOptionCurveLinear               = 3 << 16,
    
    /** 没有指定转换。 */
    UIViewAnimationOptionTransitionNone            = 0 << 20,
    /** 从左到右围绕其垂直轴翻转视图的过渡(视图的左侧向前侧和右侧向后移动) */
    UIViewAnimationOptionTransitionFlipFromLeft    = 1 << 20,
    /** 从右到左围绕其垂直轴翻转视图的过渡(视图的右侧向前侧和左侧向后移动)。 */
    UIViewAnimationOptionTransitionFlipFromRight   = 2 << 20,
    /** 从底部向上卷曲视图的过渡 */
    UIViewAnimationOptionTransitionCurlUp          = 3 << 20,
    /** 从顶部向下卷曲视图的过渡。 */
    UIViewAnimationOptionTransitionCurlDown        = 4 << 20,
    /** 从一个视图到另一个视图的过渡。 */
    UIViewAnimationOptionTransitionCrossDissolve   = 5 << 20,
    /** 从顶部到底部围绕其水平轴翻转视图的过渡(视图的顶侧向前移动,底侧向后移动)。 */
    UIViewAnimationOptionTransitionFlipFromTop     = 6 << 20,
    /** 从底部到顶部围绕其水平轴翻转视图的过渡(视图的底侧向前移动,顶侧向后移动)。 */
    UIViewAnimationOptionTransitionFlipFromBottom  = 7 << 20,
    
    /** 默认的每秒帧数。 */
    UIViewAnimationOptionPreferredFramesPerSecondDefault     = 0 << 24,
    /** 帧速率为每秒30帧。 */
    UIViewAnimationOptionPreferredFramesPerSecond60          = 3 << 24,
    /** 帧速率为每秒60帧。 */
    UIViewAnimationOptionPreferredFramesPerSecond30          = 7 << 24,
};

UIViewKeyframeAnimationOptions

/** 与animateKeyframesWithDuration:delay:options:animations:completion:方法一起使用的关键帧动画选项。 */
typedef NS_OPTIONS(NSUInteger, UIViewKeyframeAnimationOptions) {
    UIViewKeyframeAnimationOptionLayoutSubviews            = UIViewAnimationOptionLayoutSubviews,
    UIViewKeyframeAnimationOptionAllowUserInteraction      = UIViewAnimationOptionAllowUserInteraction,
    UIViewKeyframeAnimationOptionBeginFromCurrentState     = UIViewAnimationOptionBeginFromCurrentState,
    UIViewKeyframeAnimationOptionRepeat                    = UIViewAnimationOptionRepeat,
    UIViewKeyframeAnimationOptionAutoreverse               = UIViewAnimationOptionAutoreverse,
    UIViewKeyframeAnimationOptionOverrideInheritedDuration = UIViewAnimationOptionOverrideInheritedDuration,
    UIViewKeyframeAnimationOptionOverrideInheritedOptions  = UIViewAnimationOptionOverrideInheritedOptions,
    
    /** 在关键帧值之间进行插值时使用简单线性计算的选项。 */
    UIViewKeyframeAnimationOptionCalculationModeLinear     = 0 << 10,
    /** 选项不在关键帧值之间进行插值,而是直接跳转到每个新的关键帧值。 */
    UIViewKeyframeAnimationOptionCalculationModeDiscrete   = 1 << 10,
    /** 使用简单调步算法计算中间关键帧值的选项。 此选项可生成均匀节奏的动画。 */
    UIViewKeyframeAnimationOptionCalculationModePaced      = 2 << 10,
    /** 使用通过关键帧值的默认Catmull-Rom样条曲线计算中间帧的选项。 您无法调整此算法的参数。 */
    UIViewKeyframeAnimationOptionCalculationModeCubic      = 3 << 10,
    /** 使用立方体计算中间帧的选项,同时忽略动画的计时属性。 相反,隐式计算定时参数以使动画具有恒定的速度。 */
    UIViewKeyframeAnimationOptionCalculationModeCubicPaced = 4 << 10
};

UISystemAnimation

/** 动画完成时从层次结构中删除视图的选项。 */
typedef NS_ENUM(NSUInteger, UISystemAnimation) {
    /** 动画完成时从视图层次结构中删除视图的选项。 */
    UISystemAnimationDelete,
};

UIViewTintAdjustmentMode

/** 视图的色调调整模式。 */
typedef NS_ENUM(NSInteger, UIViewTintAdjustmentMode) {
    /** 视图的色调调整模式与其superview的色调调整模式相同(如果视图没有superview,则为UIViewTintAdjustmentModeNormal)。 */
    UIViewTintAdjustmentModeAutomatic,
    /** 视图的tintColor属性返回视图的完全未修改的色调颜色。 */
    UIViewTintAdjustmentModeNormal,
    /** 视图的tintColor属性返回视图原始色调颜色的去饱和,暗淡版本。 */
    UIViewTintAdjustmentModeDimmed,
};

UISemanticContentAttribute

/** 视图内容的语义描述,用于确定在从左到右和从右到左布局之间切换时是否应该翻转视图。 */
typedef NS_ENUM(NSInteger, UISemanticContentAttribute) {
    /** 视图的默认值。 在从左到右和从右到左布局之间切换时,视图会被翻转。 */
    UISemanticContentAttributeUnspecified = 0,
    /** 表示播放控件的视图,例如“播放”,“后退”或“快进”按钮或播放头擦除器。 在从左到右和从右到左布局之间切换时,不会翻转这些视图。 */
    UISemanticContentAttributePlayback,
    /** 表示方向控件的视图,例如用于文本对齐的段控件或用于游戏的D-pad控件。 在从左到右和从右到左布局之间切换时,不会翻转这些视图。 */
    UISemanticContentAttributeSpatial,
    /** 始终使用从左到右布局显示的视图。 */
    UISemanticContentAttributeForceLeftToRight,
    /** 始终使用从右到左布局显示的视图。 */
    UISemanticContentAttributeForceRightToLeft
};

@protocol UICoordinateSpace

convertPoint:toCoordinateSpace:

/**
 将点从当前对象的坐标空间转换为指定的坐标空间。
 @param point 在当前对象的坐标系中指定的点。
 @param coordinateSpace 要转换点的坐标空间。
 @return 在当前对象的坐标空间中指定的点。
 */
- (CGPoint)convertPoint:(CGPoint)point
      toCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace;

convertPoint:fromCoordinateSpace:

/**
 将指定坐标空间中的点转换为当前对象的坐标空间。
 @param point 指定坐标空间中的一个点。
 @param coordinateSpace 指定点的坐标空间。
 @return 在当前对象的坐标空间中指定的点。
 */
- (CGPoint)convertPoint:(CGPoint)point
    fromCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace;

convertRect:toCoordinateSpace:

/**
 将矩形从当前对象的坐标空间转换为指定的坐标空间。
 @param rect 在当前对象的坐标系中指定的矩形。
 @param coordinateSpace 要转换rect的坐标空间。
 @return 在目标坐标空间中指定的矩形。
 */
- (CGRect)convertRect:(CGRect)rect
    toCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace;

convertRect:fromCoordinateSpace

/**
 将矩形从指定的坐标空间转换为当前对象的坐标空间。
 @param rect 指定坐标空间中的矩形。
 @param coordinateSpace 指定rect的坐标空间。
 @return 在当前对象的坐标空间中指定的矩形。
 */
- (CGRect)convertRect:(CGRect)rect
  fromCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace;
@property (readonly, nonatomic) CGRect bounds;

UIView : UIResponder

layerClass

/** 默认值是[CALayer class]。用于为视图创建底层时。 */
@property(class, nonatomic, readonly) Class layerClass;
+ (Class)layerClass;

initWithFrame: and initWithCoder:

/** 初始化 */
- (instancetype)initWithFrame:(CGRect)frame;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder;

userInteractionEnabled

/** 是否可交互 */
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;

tag

/** 标签值, 默认0 */
@property(nonatomic) NSInteger tag;

layer

/** 返回视图的图层。将始终返回一个非nil值。视图是层的委托 */
@property(nonatomic,readonly,strong)                 CALayer  *layer;

canBecomeFocused

/** 一个布尔值,指示视图当前是否能够被聚焦,默认NO。 */
@property(nonatomic,readonly) BOOL canBecomeFocused;
- (BOOL)canBecomeFocused;

focused

/** 是否被聚焦 */
@property (readonly, nonatomic, getter=isFocused) BOOL focused NS_AVAILABLE_IOS(9_0);

semanticContentAttribute

@property (nonatomic) UISemanticContentAttribute semanticContentAttribute NS_AVAILABLE_IOS(9_0);

userInterfaceLayoutDirectionForSemanticContentAttribute:

/**
 返回给定语义内容属性的用户界面方向。
 @param attribute 视图的语义内容属性。
 @return 用户界面布局方向(从左到右或从右到左)。
 */
+ (UIUserInterfaceLayoutDirection)userInterfaceLayoutDirectionForSemanticContentAttribute:(UISemanticContentAttribute)attribute

userInterfaceLayoutDirectionForSemanticContentAttribute:relativeToLayoutDirection:

/**
 返回指定语义内容属性隐含的布局方向,相对于指定的布局方向。
 @param semanticContentAttribute 视图的语义内容属性。
 @param layoutDirection 用户界面布局方向(UIUserInterfaceLayoutDirectionLeftToRight或UIUserInterfaceLayoutDirectionRightToLeft)。
 @return 语义内容属性隐含的布局方向以及布局方向。
 */
+ (UIUserInterfaceLayoutDirection)userInterfaceLayoutDirectionForSemanticContentAttribute:(UISemanticContentAttribute)semanticContentAttribute
                                                                relativeToLayoutDirection:(UIUserInterfaceLayoutDirection)layoutDirection;

effectiveUserInterfaceLayoutDirection

/** 用户界面布局方向适合于安排视图的直接内容。 */
@property (readonly, nonatomic) UIUserInterfaceLayoutDirection effectiveUserInterfaceLayoutDirection;

UIView(UIViewGeometry)

CGAffineTransform

/** 默认为CGAffineTransformIdentity。动画 */
@property(nonatomic) CGAffineTransform transform;

contentScaleFactor

/** 应用于视图的比例因子 */
@property(nonatomic) CGFloat contentScaleFactor;

multipleTouchEnabled

/** 一个布尔值,指示视图是否一次接收多个触摸。默认NO */
@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled;

exclusiveTouch

/** 一个布尔值,指示接收器是否专门处理触摸事件。 */
@property(nonatomic,getter=isExclusiveTouch) BOOL exclusiveTouch;

hitTest:withEvent:

/**
 返回包含指定点的视图层次结构(包括其自身)中接收器的最远子类。
 @param point 接收器局部坐标系中指定的点(边界)。
 @param event 保证调用此方法的事件。 如果从事件处理代码外部调用此方法,则可以指定nil。
 @return 视图对象是当前视图的最远的后代并包含点。 如果该点完全位于接收者的视图层次结构之外,则返回nil。
 */
- (nullable UIView *)hitTest:(CGPoint)point
                   withEvent:(nullable UIEvent *)event;

pointInside:withEvent:

/**
 返回一个Bool值,判断坐标点是否在触摸接收器中
 @param point 一个坐标点
 @param event 保证调用此方法的事件。 如果从事件处理代码外部调用此方法,则可以指定nil。
 @return 如果点位于接收者的界限内,则为YES; 否则,不。
 */
- (BOOL)pointInside:(CGPoint)point
          withEvent:(nullable UIEvent *)event;

convertPoint:toView:

/**
 将指定CGPoint转换为指定视图的CGPoint
 @param point 需要被转换的CGPoint
 @param view  要转换其CGPoint的视图
              如果view为nil,则此方法将转换为窗口基坐标。
              否则,视图和接收器都必须属于同一个UIWindow对象。
 @return 转换后的CGPoint
 */
- (CGPoint)convertPoint:(CGPoint)point
                 toView:(nullable UIView *)view;

convertPoint:fromView:

/**
 将指定视图的CGPoint转换为当前视图的CGPoint
 @param point 需要被转换的CGPoint
 @param view  要转换其CGPoint的视图
              如果view为nil,则此方法将转换为窗口基坐标。
              否则,视图和接收器都必须属于同一个UIWindow对象。
 @return 转换后的CGPoint
 */
- (CGPoint)convertPoint:(CGPoint)point
               fromView:(nullable UIView *)view;

convertRect:toView:

/**
 将指定CGRect转换为指定视图的CGRect
 @param rect  需要被转换的CGRect
 @param view  要转换其CGRect的视图
              如果view为nil,则此方法将转换为窗口基坐标。
              否则,视图和接收器都必须属于同一个UIWindow对象。
 @return 转换后的CGRect
 */
- (CGRect)convertRect:(CGRect)rect 
			   toView:(nullable UIView *)view;

convertRect:fromView:

/**
 将指定视图的CGRect转换为当前视图的CGRect
 @param point 需要被转换的CGRect
 @param view  要转换其CGRect的视图
              如果view为nil,则此方法将转换为窗口基坐标。
              否则,视图和接收器都必须属于同一个UIWindow对象。
 @return 转换后的CGRect
 */
- (CGRect)convertRect:(CGRect)rect 
			 fromView:(nullable UIView *)view;

autoresizesSubviews

/** 一个布尔值,用于确定接收器在其边界更改时是否自动调整其子视图的大小。默认YES */
@property(nonatomic) BOOL autoresizesSubviews;

autoresizingMask

/** 一个整数位掩码,用于确定接收器在超视图边界发生变化时如何调整自身大小。 */
@property(nonatomic) UIViewAutoresizing autoresizingMask;

sizeThatFits:

/**
 要求视图计算并返回最适合指定CGSize的CGSize
 @param size 指定的CGSize
 @return 适合的CGSize
 */
- (CGSize)sizeThatFits:(CGSize)size;

sizeToFit

/** 调整接收器视图的大小并移动它,使其只包含其子视图。 */
- (void)sizeToFit;

UIView(UIViewHierarchy)

subviews

/** 子视图 */
@property(nonatomic,readonly,copy) NSArray<__kindof UIView *> *subviews;

removeFromSuperview

/** 删除视图 */
- (void)removeFromSuperview;

insertSubview:atIndex:

/**
 在指定索引处插入子视图
 @param view  子视图
 @param index 指定索引
 */
- (void)insertSubview:(UIView *)view
              atIndex:(NSInteger)index;

exchangeSubviewAtIndex:withSubviewAtIndex

/**
 交换两个指定索引的子视图的层级
 @param index1 子视图1
 @param index2 子视图2
 */
- (void)exchangeSubviewAtIndex:(NSInteger)index1
            withSubviewAtIndex:(NSInteger)index2;

addSubview:

/**
 添加视图
 @param view 要添加的视图
 */
- (void)addSubview:(UIView *)view;

insertSubview:belowSubview:

/**
 插入视图到指定视图的下面
 @param view 要插入的视图
 @param siblingSubview 被插入的视图
 */
- (void)insertSubview:(UIView *)view
         belowSubview:(UIView *)siblingSubview;

insertSubview:aboveSubview:

/**
 插入视图到指定视图的上面
 @param view 要插入的视图
 @param siblingSubview 被插入的视图
 */
- (void)insertSubview:(UIView *)view
         aboveSubview:(UIView *)siblingSubview;

bringSubviewToFront:

/**
 提高指定视图的层级
 @param view 指定视图
 */
- (void)bringSubviewToFront:(UIView *)view;

sendSubviewToBack:

/**
 降低指定视图的层级
 @param view 指定视图
 */
- (void)sendSubviewToBack:(UIView *)view;

didAddSubview:

/**
 告诉视图添加了一个子视图
 @param subview 子视图
 */
- (void)didAddSubview:(UIView *)subview;

willRemoveSubview:

/**
 告诉视图将要删除子视图
 @param subview 子视图
 */
- (void)willRemoveSubview:(UIView *)subview;

willMoveToSuperview:

/**
 告诉视图它的父视图即将更改为指定的父视图
 @param newSuperview 新的父视图
 */
- (void)willMoveToSuperview:(nullable UIView *)newSuperview;

didMoveToSuperview

/** 告诉视图它的父视图改变了 */
- (void)didMoveToSuperview;

willMoveToWindow:

/**
 告诉视图其Window对象即将更改
 @param newWindow 新的Window对象
 */
- (void)willMoveToWindow:(nullable UIWindow *)newWindow;

didMoveToWindow

/** 告诉视图其Window对象已经更改 */
- (void)didMoveToWindow;

isDescendantOfView:

/**
 判断调用者是否为指定视图的子视图
 @param view 指定视图
 @return 如果是子视图或者视图本身,返回YES。否则,NO
 */
- (BOOL)isDescendantOfView:(UIView *)view;

viewWithTag:

/**
 根据Tag获取指定视图上的对应Tag视图
 @param tag tag
 @return 指定tag的视图
 */
- (nullable __kindof UIView *)viewWithTag:(NSInteger)tag;

setNeedsLayout

/** 使调用者的当前布局无效并在下一个更新周期期间触发布局更新 */
- (void)setNeedsLayout;

layoutIfNeeded

/** 如果布局更新处于待处理状态,则立即布置子视图 */
- (void)layoutIfNeeded;

layoutSubviews

/** 布置子视图 */
- (void)layoutSubviews;

layoutMargins

/**
 在视图中布局内容时使用的默认间距。
 可以使用layoutMargins去定义view之间的间距,该属性只对AutoLayout布局生效。
*/
@property (nonatomic) UIEdgeInsets layoutMargins;

- (void)example1 {
    UIView *blueView = [[UIView alloc] init];
    blueView.backgroundColor = [UIColor blueColor];
    blueView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:blueView];
    NSMutableArray *constraints = [NSMutableArray array];
    [constraints addObject:[NSLayoutConstraint constraintWithItem:blueView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0]];
    [constraints addObject:[NSLayoutConstraint constraintWithItem:blueView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0.0]];
    [constraints addObject:[NSLayoutConstraint constraintWithItem:blueView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
    [constraints addObject:[NSLayoutConstraint constraintWithItem:blueView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0]];
    [self.view addConstraints:constraints];

    UIView *yellowView = [[UIView alloc] init];
    yellowView.backgroundColor = [UIColor yellowColor];
    yellowView.translatesAutoresizingMaskIntoConstraints = NO;
    [blueView addSubview:yellowView];
    [constraints removeAllObjects];
    [constraints addObject:[NSLayoutConstraint constraintWithItem:yellowView attribute:NSLayoutAttributeLeftMargin relatedBy:NSLayoutRelationEqual toItem:blueView attribute:NSLayoutAttributeLeftMargin multiplier:1.0 constant:0.0]];
    [constraints addObject:[NSLayoutConstraint constraintWithItem:yellowView attribute:NSLayoutAttributeRightMargin relatedBy:NSLayoutRelationEqual toItem:blueView attribute:NSLayoutAttributeRightMargin multiplier:1.0 constant:0.0]];
    [constraints addObject:[NSLayoutConstraint constraintWithItem:yellowView attribute:NSLayoutAttributeTopMargin relatedBy:NSLayoutRelationEqual toItem:blueView attribute:NSLayoutAttributeTopMargin multiplier:1.0 constant:0.0]];
    [constraints addObject:[NSLayoutConstraint constraintWithItem:yellowView attribute:NSLayoutAttributeBottomMargin relatedBy:NSLayoutRelationEqual toItem:blueView attribute:NSLayoutAttributeBottomMargin multiplier:1.0 constant:0.0]];
    [blueView addConstraints:constraints];

    blueView.layoutMargins = UIEdgeInsetsMake(50, 50, 50, 50);
}

directionalLayoutMargins

/** 考虑当前语言方向时,在视图中布局内容时使用的默认间距 */
@property (nonatomic) NSDirectionalEdgeInsets directionalLayoutMargins;

preservesSuperviewLayoutMargins

/** 判断当前视图是否也遵循其父视图的边距。 */
@property (nonatomic) BOOL preservesSuperviewLayoutMargins;

insetsLayoutMarginsFromSafeArea

/** 判断视图的布局边距是否自动更新以反映安全区域,默认YES */
@property (nonatomic) BOOL insetsLayoutMarginsFromSafeArea;

layoutMarginsDidChange

/** 告诉视图布局边距已更改 */
- (void)layoutMarginsDidChange;

safeAreaInsets

/** 用于确定此视图的安全区域的插图。 */

@property (nonatomic,readonly) UIEdgeInsets safeAreaInsets;

safeAreaInsetsDidChange

/** 在视图的安全区域发生更改时调用 */
- (void)safeAreaInsetsDidChange;

layoutMarginsGuide

/** 表示视图边距的布局指南 */
@property(readonly,strong) UILayoutGuide *layoutMarginsGuide;

readableContentGuide

/** 布局指南,表示视图中具有可读宽度的区域。 */
@property (nonatomic, readonly, strong) UILayoutGuide *readableContentGuide;

safeAreaLayoutGuide

/** 布局指南,表示视图中不受条形和其他内容影响的部分。 */
@property(nonatomic,readonly,strong) UILayoutGuide *safeAreaLayoutGuide;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值