API_UIView記錄

對API中的UIView的屬性李请、方法以及使用的記錄

今天先發(fā)一篇UIView的API記錄交煞,之后會陸續(xù)發(fā)一些其他類的API記錄。代碼鏈接在本文最下方碌秸,歡迎Star或者Fark。

//
//  UIView.h
//  UIKit
//
//  Copyright (c) 2005-2015 Apple Inc. All rights reserved.
//
//  Coder_Sun的GitHub地址:https://github.com/272095249
//  Coder_Sun簡書網(wǎng)址:http://www.reibang.com/u/87c7aa9de064
//  

#import <Foundation/Foundation.h>
#import <UIKit/UIResponder.h>
#import <UIKit/UIInterface.h>
#import <UIKit/UIKitDefines.h>
#import <UIKit/UIAppearance.h>
#import <UIKit/UIDynamicBehavior.h>
#import <UIKit/NSLayoutConstraint.h>
#import <UIKit/UITraitCollection.h>
#import <UIKit/UIFocus.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {
    UIViewAnimationCurveEaseInOut,         // slow at beginning and end
    UIViewAnimationCurveEaseIn,            // slow at beginning
    UIViewAnimationCurveEaseOut,           // slow at end
    UIViewAnimationCurveLinear
};
設(shè)置圖片的顯示方式
typedef NS_ENUM(NSInteger, UIViewContentMode) {
    /**
     *  填充  根據(jù)視圖的比例去拉伸圖片內(nèi)容
     */
    UIViewContentModeScaleToFill,
    /**
     *  縮放填充   保持圖片內(nèi)容的縱橫比例悄窃,來適應(yīng)視圖的大小
     */
    UIViewContentModeScaleAspectFit,
    /**
     *  用圖片內(nèi)容來填充視圖的大小讥电,多余的部分可以被修剪掉來填充整個視圖邊界
     */
    UIViewContentModeScaleAspectFill,
    /**
     *  重繪邊界   這個選項是單視圖的尺寸位置發(fā)生變化的時候通過調(diào)用setNeedsDisplay方法來重新顯示
     */
    UIViewContentModeRedraw,
    /**
     *  保持圖片原比例,居中
     */
    UIViewContentModeCenter,
    /**
     *  保持圖片原比例广匙,居上
     */
    UIViewContentModeTop,
    /**
     *  保持圖片原比例允趟,居下
     */
    UIViewContentModeBottom,
    /**
     *  保持圖片原比例,居左
     */
    UIViewContentModeLeft,
    /**
     *  保持圖片原比例鸦致,居右
     */
    UIViewContentModeRight,
    /**
     *  保持圖片原比例潮剪,居左上
     */
    UIViewContentModeTopLeft,
    /**
     *  保持圖片原比例,居右上
     */
    UIViewContentModeTopRight,
    /**
     *  保持圖片原比例分唾,居左下
     */
    UIViewContentModeBottomLeft,
    /**
     *  保持圖片原比例抗碰,居右下
     */
    UIViewContentModeBottomRight,
};
過渡動畫
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
    /**
     *  正常
     */
    UIViewAnimationTransitionNone,
    /**
     *  從左向右翻
     */
    UIViewAnimationTransitionFlipFromLeft,
    /**
     *  從右向左翻
     */
    UIViewAnimationTransitionFlipFromRight,
    /**
     *  從下向上卷
     */
    UIViewAnimationTransitionCurlUp,
    /**
     *  從上向下卷
     */
    UIViewAnimationTransitionCurlDown,
};
自適應(yīng)枚舉
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
    /**
     *  視圖將不進(jìn)行自動尺寸調(diào)整
     */
    UIViewAutoresizingNone                 = 0,
    /**
     *  視圖的左邊界將隨著父視圖寬度的變化而按比例進(jìn)行調(diào)整。否則绽乔,視圖和其父視圖的左邊界的相對位置將保持不變弧蝇。
     */
    UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
    /**
     *  視圖的寬度將和父視圖的寬度一起成比例變化。否則折砸,視圖的寬度將保持不變
     */
    UIViewAutoresizingFlexibleWidth        = 1 << 1,
    /**
     *  視圖的右邊界將隨著父視圖寬度的變化而按比例進(jìn)行調(diào)整看疗。否則,視圖和其父視圖的右邊界的相對位置將保持不變睦授。
     */
    UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
    /**
     *  視圖的上邊界將隨著父視圖高度的變化而按比例進(jìn)行調(diào)整两芳。否則,視圖和其父視圖的上邊界的相對位置將保持不變去枷。
     */
    UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
    /**
     *  視圖的高度將和父視圖的高度一起成比例變化怖辆。否則,視圖的高度將保持不變
     */
    UIViewAutoresizingFlexibleHeight       = 1 << 4,
    /**
     *  視圖的底邊界將隨著父視圖高度的變化而按比例進(jìn)行調(diào)整删顶。否則竖螃,視圖和其父視圖的底邊界的相對位置將保持不變。
     */
    UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
動畫執(zhí)行選項設(shè)置
typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {
    
// 這部分是基礎(chǔ)屬性的設(shè)置
    /**
     *  提交動畫的時候布局子控件逗余,表示子控件將和父控件一同動畫特咆。
     */
    UIViewAnimationOptionLayoutSubviews            = 1 <<  0,
    /**
     *  動畫時允許用戶交流,比如觸摸
     */
    UIViewAnimationOptionAllowUserInteraction      = 1 <<  1,
    /**
     *  從當(dāng)前狀態(tài)開始動畫
     */
    UIViewAnimationOptionBeginFromCurrentState     = 1 <<  2,
    /**
     *  動畫無限重復(fù)
     */
    UIViewAnimationOptionRepeat                    = 1 <<  3,
    /**
     *  動畫運行到結(jié)束點后仍然以動畫方式回到初始點,前提是設(shè)置動畫無限重復(fù)   (Auto reverse:自動翻轉(zhuǎn))
     */
    UIViewAnimationOptionAutoreverse               = 1 <<  4,
    /**
     *  忽略嵌套動畫時間設(shè)置
     */
    UIViewAnimationOptionOverrideInheritedDuration = 1 <<  5,
    /**
     *  忽略嵌套動畫速度設(shè)置
     */
    UIViewAnimationOptionOverrideInheritedCurve    = 1 <<  6,
    /**
     *  動畫過程中重繪視圖(注意僅僅適用于轉(zhuǎn)場動畫)
     */
    UIViewAnimationOptionAllowAnimatedContent      = 1 <<  7,
    /**
     *  視圖切換時直接隱藏舊視圖猎荠、顯示新視圖坚弱,而不是將舊視圖從父視圖移除(僅僅適用于轉(zhuǎn)場動畫)
     */
    UIViewAnimationOptionShowHideTransitionViews   = 1 <<  8,
    /**
     *  不繼承父動畫設(shè)置或動畫類型蜀备。
     */
    UIViewAnimationOptionOverrideInheritedOptions  = 1 <<  9,
動畫速度控制(可從其中選擇一個設(shè)置)
    /**
     *  動畫先緩慢关摇,然后逐漸加速(淡入淡出)
     */
    UIViewAnimationOptionCurveEaseInOut            = 0 << 16,
    /**
     *  動畫逐漸變慢(淡入)
     */
    UIViewAnimationOptionCurveEaseIn               = 1 << 16,
    /**
     *  動畫逐漸加速(淡出)
     */
    UIViewAnimationOptionCurveEaseOut              = 2 << 16,
    /**
     *  動畫勻速執(zhí)行荒叶,默認(rèn)值(線性,勻速執(zhí)行)
     */
    UIViewAnimationOptionCurveLinear               = 3 << 16,
轉(zhuǎn)場類型

(僅適用于轉(zhuǎn)場動畫設(shè)置输虱,可以從中選擇一個進(jìn)行設(shè)置些楣,基本動畫、關(guān)鍵幀動畫不需要設(shè)置)

    /**
     *  沒有轉(zhuǎn)場動畫效果
     */
    UIViewAnimationOptionTransitionNone            = 0 << 20,
    /**
     *  從左側(cè)翻轉(zhuǎn)效果
     */
    UIViewAnimationOptionTransitionFlipFromLeft    = 1 << 20,
    /**
     *  從右側(cè)翻轉(zhuǎn)效果
     */
    UIViewAnimationOptionTransitionFlipFromRight   = 2 << 20,
    /**
     *  向后翻頁的動畫過渡效果
     */
    UIViewAnimationOptionTransitionCurlUp          = 3 << 20,
    /**
     *  向前翻頁的動畫過渡效果
     */
    UIViewAnimationOptionTransitionCurlDown        = 4 << 20,
    /**
     *  舊視圖溶解消失顯示下一個新視圖的效果(溶解效果)
     */
    UIViewAnimationOptionTransitionCrossDissolve   = 5 << 20,
    /**
     *  從上方翻轉(zhuǎn)效果
     */
    UIViewAnimationOptionTransitionFlipFromTop     = 6 << 20,
    /**
     *  從底部翻轉(zhuǎn)效果
     */
    UIViewAnimationOptionTransitionFlipFromBottom  = 7 << 20,
    
    
/*
    關(guān)于最后一組轉(zhuǎn)場動畫它一般是用在這個方法中的:
        [UIView transitionFromView: toView: duration: options: completion:^(BOOL finished) {}];
    該方法效果是插入一面視圖移除一面視圖宪睹,期間可以使用一些轉(zhuǎn)場動畫效果
 
 */
    
    
} NS_ENUM_AVAILABLE_IOS(4_0);
};
關(guān)鍵幀動畫效果選項
typedef NS_OPTIONS(NSUInteger, UIViewKeyframeAnimationOptions) {
    /**
     *  動畫過程中保證子視圖跟隨運動
     */
    UIViewKeyframeAnimationOptionLayoutSubviews            = UIViewAnimationOptionLayoutSubviews,
    /**
     *  動畫過程中允許用戶交互
     */
    UIViewKeyframeAnimationOptionAllowUserInteraction      = UIViewAnimationOptionAllowUserInteraction,
    /**
     *  所有視圖從當(dāng)前狀態(tài)開始運行
     */
    UIViewKeyframeAnimationOptionBeginFromCurrentState     = UIViewAnimationOptionBeginFromCurrentState,
    /**
     *  重復(fù)運行動畫
     */
    UIViewKeyframeAnimationOptionRepeat                    = UIViewAnimationOptionRepeat,
    /**
     *  動畫運行到結(jié)束點后仍然以動畫方式回到初始點
     */
    UIViewKeyframeAnimationOptionAutoreverse               = UIViewAnimationOptionAutoreverse,
    /**
     *  忽略嵌套動畫時間設(shè)置
     */
    UIViewKeyframeAnimationOptionOverrideInheritedDuration = UIViewAnimationOptionOverrideInheritedDuration,
    /**
     *  不繼承父動畫設(shè)置或動畫類型
     */
    UIViewKeyframeAnimationOptionOverrideInheritedOptions  = UIViewAnimationOptionOverrideInheritedOptions,
動畫模式設(shè)置

(同前面關(guān)鍵幀動畫模式一一對應(yīng)愁茁,可以從其中選擇一個進(jìn)行設(shè)置)

    /**
     *  連續(xù)運算模式
     */
    UIViewKeyframeAnimationOptionCalculationModeLinear     = 0 << 10,
    /**
     *  離散運算模式
     */
    UIViewKeyframeAnimationOptionCalculationModeDiscrete   = 1 << 10,
    /**
     *  均勻執(zhí)行運算模式
     */
    UIViewKeyframeAnimationOptionCalculationModePaced      = 2 << 10,
    /**
     *  平滑運算模式
     */
    UIViewKeyframeAnimationOptionCalculationModeCubic      = 3 << 10,
    /**
     *  平滑均勻運算模式
     */
    UIViewKeyframeAnimationOptionCalculationModeCubicPaced = 4 << 10 } NS_ENUM_AVAILABLE_IOS(7_0);
};

typedef NS_ENUM(NSUInteger, UISystemAnimation) {
    UISystemAnimationDelete,    // removes the views from the hierarchy when complete
} NS_ENUM_AVAILABLE_IOS(7_0);
定義了tint color的調(diào)整模式
typedef NS_ENUM(NSInteger, UIViewTintAdjustmentMode) {
    /**
     *  視圖的著色調(diào)整模式與父視圖一致(自動的)
     */
    UIViewTintAdjustmentModeAutomatic,
    /**
     *  視圖的tintColor屬性返回完全未修改的視圖著色顏色(正常的)
     */
    UIViewTintAdjustmentModeNormal,
    /**
     *  視圖的tintColor屬性返回一個去飽和度的、變暗的視圖著色顏色(暗淡的)
     */
    UIViewTintAdjustmentModeDimmed,
    
    /**
     * (相關(guān)鏈接: http://www.cocoachina.com/ios/20150703/12363.html?utm_medium=referral&utm_source=pulsenews)
     */
    
} NS_ENUM_AVAILABLE_IOS(7_0);
};
改變界面布局方式

對于有些國家來說亭病,他們是從右往左閱讀的 下面是強制效果和未用效果

typedef NS_ENUM(NSInteger, UISemanticContentAttribute) {
    /**
     *  語義內(nèi)容未指明
     */
    UISemanticContentAttributeUnspecified = 0,
    /**
     *  適合于回放控制例如Play/RW/FF按鈕和播放頭洗滌器
     */
    UISemanticContentAttributePlayback,
    /**
     *  適合于控制那些稍微方向改變在ui.例如 一個語句控制對文本對齊或者 一個d-pad 在游戲中
     */
    UISemanticContentAttributeSpatial,
    /**
     *  視圖總是從左向右布局
     */
    UISemanticContentAttributeForceLeftToRight,
    /**
     *  視圖總是從右向左布局
     */
    UISemanticContentAttributeForceRightToLeft
} NS_ENUM_AVAILABLE_IOS(9_0);
};
Description
typedef NS_ENUM(NSInteger, UIUserInterfaceLayoutDirection) {
    /**
     *  從左到右的布局
     */
    UIUserInterfaceLayoutDirectionLeftToRight,
    /**
     *  從右到左的布局
     */
    UIUserInterfaceLayoutDirectionRightToLeft,
    
} NS_ENUM_AVAILABLE_IOS(5_0);
};

UICoordinateSpace

@protocol UICoordinateSpace <NSObject>

// 相對于某個坐標(biāo)轉(zhuǎn)換坐標(biāo)  ios8.0之后可用
- (CGPoint)convertPoint:(CGPoint)point toCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace NS_AVAILABLE_IOS(8_0);

//從坐標(biāo)轉(zhuǎn)換坐標(biāo)
- (CGPoint)convertPoint:(CGPoint)point fromCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace NS_AVAILABLE_IOS(8_0);

//相對于可見區(qū)域轉(zhuǎn)換區(qū)域
- (CGRect)convertRect:(CGRect)rect toCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace NS_AVAILABLE_IOS(8_0);

//從可見區(qū)域轉(zhuǎn)換區(qū)域
- (CGRect)convertRect:(CGRect)rect fromCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace NS_AVAILABLE_IOS(8_0);

@property (readonly, nonatomic) CGRect bounds NS_AVAILABLE_IOS(8_0);  // 只讀協(xié)議bounds屬性

@end

@class UIBezierPath, UIEvent, UIWindow, UIViewController, UIColor, UIGestureRecognizer, UIMotionEffect, CALayer, UILayoutGuide;

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIView : UIResponder <NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem, UITraitEnvironment, UICoordinateSpace, UIFocusEnvironment>

+ (Class)layerClass;                        // UIView有個layer屬性鹅很,可以返回它的主CALayer實例,UIView有一個layerClass方法罪帖,返回主layer所使用的類促煮,UIView的子類可以通過重載這個方法來讓UIView使用不同的CALayer來顯示

- (instancetype)initWithFrame:(CGRect)frame;          // 便利初始化方法:根據(jù)frame創(chuàng)建視圖
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;    // 實例化從序列化

@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;  // 是否可以與用戶交互
@property(nonatomic)                                 NSInteger tag;                // 當(dāng)前視圖的標(biāo)簽,默認(rèn)是0
@property(nonatomic,readonly,strong)                 CALayer  *layer;              // 用來視圖渲染的核心動畫層

- (BOOL)canBecomeFocused NS_AVAILABLE_IOS(9_0); // NO by default  // 可成為焦點,默認(rèn)為no
@property (readonly, nonatomic, getter=isFocused) BOOL focused NS_AVAILABLE_IOS(9_0);

// 用戶交互布局繼承從語義內(nèi)容屬性
+ (UIUserInterfaceLayoutDirection)userInterfaceLayoutDirectionForSemanticContentAttribute:(UISemanticContentAttribute)attribute NS_AVAILABLE_IOS(9_0);
@property (nonatomic) UISemanticContentAttribute semanticContentAttribute NS_AVAILABLE_IOS(9_0);    // 語義布局屬性
@end

UIView(UIViewGeometry)——關(guān)于UIView幾何方面的分類

@interface UIView(UIViewGeometry)

@property(nonatomic) CGRect            frame;   // 當(dāng)前視圖的邊界整袁,包括大小和原點菠齿,這里是在父視圖的坐標(biāo)系下

// use bounds/center and not frame if non-identity transform. if bounds dimension is odd, center may be have fractional part
@property(nonatomic) CGRect            bounds;      // 當(dāng)前視圖的邊界,包括大小和原點坐昙,這里是在自己的坐標(biāo)系下
@property(nonatomic) CGPoint           center;      // 當(dāng)前視圖的中心绳匀,并制定是在父視圖的坐標(biāo)系下
@property(nonatomic) CGAffineTransform transform;   // 形變屬性(平移/縮放/旋轉(zhuǎn))
/*
 CGAffineTransform結(jié)構(gòu)體,有六個值,分別是:
 CGFloat a, b, c, d;
 CGFloat tx, ty;
 */
@property(nonatomic) CGFloat           contentScaleFactor;      // 應(yīng)用到當(dāng)前視圖的比例Scale

@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled __TVOS_PROHIBITED;   // 是否支持多點觸控炸客,默認(rèn)是NO
@property(nonatomic,getter=isExclusiveTouch) BOOL       exclusiveTouch __TVOS_PROHIBITED;         // 決定當(dāng)前視圖是否是處理觸摸事件的唯一對象疾棵,默認(rèn)為NO

- (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event;   // 此方法可試下點擊穿透活孩、點擊下層視圖功能
/*
 
 方法測試:
     繼承UIView創(chuàng)建一個view益老,在.m文件中寫
     - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event  {
     
         UIView *hitView = [super hitTest:point withEvent:event];
         if (point.x <= self.center.x) {
             hitView = nil;
         }
         return hitView;
     }
     
     然后在viewController中初始化View,然后添加touch事件
     - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
     
         UITouch * touch = touches.anyObject;
         NSLog(@"%@",touch.view);
     }

    這樣如果點擊的是view中心點左邊視圖則是父視圖響應(yīng)荆几,點擊view中心店右邊視圖則是此視圖響應(yīng)
 
 */
- (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event;   // 這個函數(shù)的用處是判斷當(dāng)前的點擊或者觸摸事件的點是否在當(dāng)前的View中

- (CGPoint)convertPoint:(CGPoint)point toView:(nullable UIView *)view;      // 把本地視圖(調(diào)用者)下的point(第一參數(shù))轉(zhuǎn)換為指定View(第二參數(shù))的point(返回值)
- (CGPoint)convertPoint:(CGPoint)point fromView:(nullable UIView *)view;    // 把指定View(第二參數(shù))下的point(第一參數(shù))轉(zhuǎn)化為本地視圖(調(diào)用者)的point(返回值)
- (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;      // 把本地視圖(調(diào)用者)下的rect(第一參數(shù))轉(zhuǎn)換為指定View(第二參數(shù))的rect(返回值)
- (CGRect)convertRect:(CGRect)rect fromView:(nullable UIView *)view;        // 把指定View(第二參數(shù))下的rect(第一參數(shù))轉(zhuǎn)化為本地視圖(調(diào)用者)的rect(返回值)


/**
 *  當(dāng)你改變視圖的邊框矩形時蝶溶,其內(nèi)嵌的子視圖的位置和尺寸往往需要改變嗜历,以適應(yīng)原始視圖的新尺寸。如果視圖的autoresizesSubViews屬性聲明被設(shè)置為YES抖所,其子視圖會根據(jù)autoresizingMask屬性的值自動進(jìn)行尺寸調(diào)整
 */
@property(nonatomic) BOOL               autoresizesSubviews; // 這個屬性是決定當(dāng)視圖大小邊界發(fā)生改變時梨州,其子視圖是否也跟著自動調(diào)整大小,默認(rèn)為YES
/**
 *  設(shè)置視圖的自動尺寸調(diào)整行為的方法是通過OR操作符將期望的自定尺寸調(diào)整常量連接起來田轧。并將結(jié)果賦值給視圖的autoresizingMask屬性暴匠。比如要使一個視圖和其父視圖左下角的相對位置保持不變可以加入UIViewAutoresizingFlexibleRightMargin
 */
@property(nonatomic) UIViewAutoresizing autoresizingMask;    // 決定當(dāng)當(dāng)前視圖的父視圖大小發(fā)生變化時,當(dāng)前視圖該怎么調(diào)整自己的size
/*
 
 UIViewAutoresizing枚舉值:
 UIViewAutoresizingNone                 //視圖將不進(jìn)行自動尺寸調(diào)整傻粘。
 UIViewAutoresizingFlexibleHeight       //視圖的高度將和父視圖的高度一起成比例變化每窖。否則帮掉,視圖的高度將保持不變
 UIViewAutoresizingFlexibleWidth        //視圖的寬度將和父視圖的寬度一起成比例變化。否則窒典,視圖的寬度將保持不變
 UIViewAutoresizingFlexibleLeftMargin   //視圖的左邊界將隨著父視圖寬度的變化而按比例進(jìn)行調(diào)整蟆炊。否則,視圖和其父視圖的左邊界的相對位置將保持不變瀑志。
 UIViewAutoresizingFlexibleRightMargin  //視圖的右邊界將隨著父視圖寬度的變化而按比例進(jìn)行調(diào)整涩搓。否則,視圖和其父視圖的右邊界的相對位置將保持不變劈猪。
 UIViewAutoresizingFlexibleBottomMargin //視圖的底邊界將隨著父視圖高度的變化而按比例進(jìn)行調(diào)整昧甘。否則,視圖和其父視圖的底邊界的相對位置將保持不變战得。
 UIViewAutoresizingFlexibleTopMargin    //視圖的上邊界將隨著父視圖高度的變化而按比例進(jìn)行調(diào)整充边。否則,視圖和其父視圖的上邊界的相對位置將保持不變常侦。
 
 */

- (CGSize)sizeThatFits:(CGSize)size;     // 返回最符合其子視圖的大小浇冰。返回最佳尺寸,默認(rèn)返回self.frame.size
- (void)sizeToFit;                       // 移動并調(diào)整子視圖的大小

@end

UIView(UIViewHierarchy)——UIVew層級

@interface UIView(UIViewHierarchy)

@property(nullable, nonatomic,readonly) UIView       *superview;    // 獲取父視圖刮吧,只讀屬性
@property(nonatomic,readonly,copy) NSArray<__kindof UIView *> *subviews;    // 當(dāng)前視圖的所有子視圖湖饱,只讀屬性
@property(nullable, nonatomic,readonly) UIWindow     *window;       // 當(dāng)前視圖上的UIWindow對象,只讀屬性

- (void)removeFromSuperview;        // 從父視圖移除
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;      // 在索引位置插入一個視圖
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;      // 用索引值交換兩個視圖

- (void)addSubview:(UIView *)view;      // 向當(dāng)前視圖上添加子視圖
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;     // 在某個視圖下插入一個視圖
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;     // 在某個視圖上插入一個視圖

- (void)bringSubviewToFront:(UIView *)view;     // 把這個View放到最前面
- (void)sendSubviewToBack:(UIView *)view;       // 把這個View放到最后面

- (void)didAddSubview:(UIView *)subview;        // 告訴視圖添加子視圖
- (void)willRemoveSubview:(UIView *)subview;        // 即將移除子視圖

- (void)willMoveToSuperview:(nullable UIView *)newSuperview;        // 即將從父視圖移除
- (void)didMoveToSuperview;     // 已經(jīng)移除杀捻,父視圖改變
- (void)willMoveToWindow:(nullable UIWindow *)newWindow;        // 窗口對象即將改變
- (void)didMoveToWindow;        // 已經(jīng)語出窗體對象

#pragma mark - 系統(tǒng)自動調(diào)用
- (BOOL)isDescendantOfView:(UIView *)view;  // 判定一個視圖是否在其父視圖的視圖層中
- (nullable __kindof UIView *)viewWithTag:(NSInteger)tag; // 返回指定tag的View


#pragma mark - 布局

- (void)setNeedsLayout;     // 標(biāo)記視圖需要重新布局井厌,會調(diào)用layoutSubviews
- (void)layoutIfNeeded;     // 當(dāng)調(diào)用了setNeedsLayout并不會馬上調(diào)用layoutSubViews,這時會調(diào)用該方法致讥,可以強制發(fā)生重新布局

#pragma mark - 系統(tǒng)自動調(diào)用(留給子類去實現(xiàn))
/**
 *  控件的frame仅仆,約束發(fā)生改變的時候就會調(diào)用,一般在這里重寫布局子控件的位置和尺寸
 *  重寫了這個方法后一定要調(diào)用[super layoutSubviews]
 */
- (void)layoutSubviews;    // 對子視圖布局
/*
 
 layoutSubviews在以下情況下會被調(diào)用:
 1垢袱、init初始化不會觸發(fā)layoutSubviews ,  但 initWithFrame 進(jìn)行初始化時墓拜,當(dāng)rect的值不為CGRectZero時,也會觸發(fā).
 2、addSubview會觸發(fā)layoutSubviews.
 3请契、設(shè)置view的Frame會觸發(fā)layoutSubviews咳榜,當(dāng)然前提是frame的值設(shè)置前后發(fā)生了變化.
 4、滾動一個UIScrollView會觸發(fā)layoutSubviews.
 5爽锥、旋轉(zhuǎn)Screen會觸發(fā)父UIView上的layoutSubviews事件.
 6涌韩、改變一個UIView大小的時候也會觸發(fā)父UIView上的layoutSubviews事件.
 [1]、layoutSubviews對subviews重新布局
 [2]氯夷、layoutSubviews方法調(diào)用先于drawRect
 [3]臣樱、setNeedsLayout在receiver標(biāo)上一個需要被重新布局的標(biāo)記,在系統(tǒng)runloop的下一個周期自動調(diào)用layoutSubviews
 [4]、layoutIfNeeded方法如其名雇毫,UIKit會判斷該receiver是否需要layout
 [5]玄捕、layoutIfNeeded遍歷的不是superview鏈,應(yīng)該是subviews鏈
 
 */



@property (nonatomic) UIEdgeInsets layoutMargins;   // 布局視圖棚放,距離父視圖的上左下右的距離
@property (nonatomic) BOOL preservesSuperviewLayoutMargins; // 這個屬性默認(rèn)是NO枚粘,如果把它設(shè)為YES,layoutMargins會根據(jù)屏幕中相關(guān)View的布局而改變
- (void)layoutMarginsDidChange;     // 在我們改變View的layoutMargins這個屬性時席吴,會觸發(fā)這個方法赌结。我們在自己的View里面可以重寫這個方法來捕獲layoutMargins的變化捞蛋。在大多數(shù)情況下孝冒,我們可以在這個方法里觸發(fā)drawing和layout的Update


@property(readonly,strong) UILayoutGuide *layoutMarginsGuide NS_AVAILABLE_IOS(9_0);

// This content guide provides a layout area that you can use to place text and related content whose width should generally be constrained to a size that is easy for the user to read. This guide provides a centered region that you can place content within to get this behavior for this view.
// 這個內(nèi)容指南提供一個布局區(qū)域,是你可以使用放置文本和相關(guān)文本,它的寬度應(yīng)該一般約束去一個尺寸,它很容易去使用和閱讀.
@property (nonatomic, readonly, strong) UILayoutGuide *readableContentGuide  NS_AVAILABLE_IOS(9_0);
@end

UIView(UIViewRendering)——UIView渲染

@interface UIView(UIViewRendering)
/**
 *  drawRect是對receiver的重繪
 *  setNeedDisplay在receiver標(biāo)上一個需要被重新繪圖的標(biāo)記,在下一個draw周期自動重繪拟杉,iphone device的刷新頻率是60hz庄涡,也就是1/60秒后重繪
 */
- (void)drawRect:(CGRect)rect;      // 渲染 重寫此方法 執(zhí)行重繪

- (void)setNeedsDisplay;    // 需要重新渲染  標(biāo)記為需要重繪 一步調(diào)用drawRect
- (void)setNeedsDisplayInRect:(CGRect)rect;     // 需要重新渲染某一塊區(qū)域

@property(nonatomic)                 BOOL              clipsToBounds;              // 決定了子視圖的顯示范圍。具體來說搬设,當(dāng)取值為YES時穴店,裁剪超出父視圖范圍的子視圖范圍
@property(nullable, nonatomic,copy)            UIColor          *backgroundColor;  // 設(shè)置背景顏色
@property(nonatomic)                 CGFloat           alpha;                      // 透明度,0.0-1.0的數(shù)值拿穴,0為全透明泣洞,1為不透明
@property(nonatomic,getter=isOpaque) BOOL              opaque;                     // 是否透明,默認(rèn)為YES
/*
 決定該消息接收者(UIView instance)是否讓其視圖不透明,用處在于給繪圖系統(tǒng)提供一個性能優(yōu)化開關(guān)默色。
 myView.opaque = NO;
 該值為YES, 那么繪圖在繪制該視圖的時候把整個視圖當(dāng)作不透明對待球凰。優(yōu)化繪圖過程并提升系統(tǒng)性能;為了性能方面的考量腿宰,默認(rèn)被置為YES呕诉。
 該值為NO,,不去做優(yōu)化操作吃度。
 一個不透明視圖需要整個邊界里面的內(nèi)容都是不透明甩挫。基于這個原因椿每,opaque設(shè)置為YES伊者,要求對應(yīng)的alpha必須為1.0。如果一個UIView實例opaque被設(shè)置為YES, 而同時它又沒有完全填充它的邊界(bounds),或者它包含了整個或部分的透明的內(nèi)容視圖间护,那么將會導(dǎo)致未知的結(jié)果亦渗。
 因此,如果視圖部分或全部支持透明兑牡,那么你必須把opaque這個值設(shè)置為NO.
 */

@property(nonatomic)                 BOOL              clearsContextBeforeDrawing; // 決定在子視圖重畫之前是否先清理視圖以前的內(nèi)容
@property(nonatomic,getter=isHidden) BOOL              hidden;                     // 是否隱藏央碟,默認(rèn)為NO
@property(nonatomic)                 UIViewContentMode contentMode;                // 決定當(dāng)視圖邊界變時呈現(xiàn)視圖內(nèi)容的方式
/*
 UIViewContentMode枚舉值:
 UIViewContentModeScaleToFill                // 填充
 UIViewContentModeScaleAspectFit             // 縮放填充
 UIViewContentModeRedraw                     // 重繪邊界
 UIViewContentModeCenter                     // 保持相同的大小,居中
 UIViewContentModeTop                        // 保持相同的大小,居上
 UIViewContentModeBottom,                    // 保持相同的大小亿虽,居下
 UIViewContentModeLeft,                      // 保持相同的大小菱涤,居左
 UIViewContentModeRight,                     // 保持相同的大小,居右
 UIViewContentModeTopLeft,                   // 保持相同的大小洛勉,居左上
 UIViewContentModeTopRight,                  // 保持相同的大小粘秆,居右上
 UIViewContentModeBottomLeft,                // 保持相同的大小,居左下
 UIViewContentModeBottomRight,               // 保持相同的大小收毫,居右下
 */
@property(nonatomic)                 CGRect            contentStretch; // 用于制定那部分是可拉伸的攻走,取值在0.0~1.0之間
/*
 [imageView setContentStretch:CGRectMake(150.0/300.0, 100.0/200.0, 10.0/300.0, 10.0/200.0)];
 
    image.png的大小是 200  x  150 ;
    mageView的frame是(0此再,0昔搂,300,200)输拇;
    150.0/300.0表示x軸上摘符,前150個像素不進(jìn)行拉伸。
    100.0/200.0表示y軸上策吠,前100個像素不進(jìn)行拉伸逛裤。
    10.0/300.0表示x軸上150后的10個像素(151-160)進(jìn)行拉伸,直到image.png鋪滿imageView猴抹。
    10.0/200.0表示y軸上100后的10個像素(101-110)進(jìn)行拉伸带族,直到image.png鋪滿imageView。
 */

@property(nullable, nonatomic,strong)          UIView           *maskView;  // 模具視圖


@property(null_resettable, nonatomic, strong) UIColor *tintColor;     // 視圖控件的顏色

@property(nonatomic) UIViewTintAdjustmentMode tintAdjustmentMode;     // 視圖的色彩模式
/*
 枚舉值:
    UIViewTintAdjustmentModeAutomatic,      //自動的
    UIViewTintAdjustmentModeNormal,         //正常的
    UIViewTintAdjustmentModeDimmed,         //暗淡的
 */


- (void)tintColorDidChange;     // 視圖顏色屬性發(fā)生變化時蟀给,由系統(tǒng)調(diào)用

@end

UIView(UIViewAnimation)——動畫

@interface UIView(UIViewAnimation)

+ (void)beginAnimations:(nullable NSString *)animationID context:(nullable void *)context;  // 用來表示動畫的開始
+ (void)commitAnimations;                                                 // 標(biāo)記動畫結(jié)束蝙砌,執(zhí)行動畫(與beginAnimations方法成對使用)


+ (void)setAnimationDelegate:(nullable id)delegate;                          // 設(shè)置動畫代理對象,當(dāng)動畫開始或者結(jié)束時會發(fā)消息給代理對象
+ (void)setAnimationWillStartSelector:(nullable SEL)selector;                // 當(dāng)動畫即將開始時坤溃,執(zhí)行delegate對象的selector拍霜,并且把beginAnimations:context:中傳入的參數(shù)傳進(jìn)selector
+ (void)setAnimationDidStopSelector:(nullable SEL)selector;                  // 當(dāng)動畫結(jié)束時,執(zhí)行delegate對象的selector薪介,并且把beginAnimations:context:中傳入的參數(shù)傳進(jìn)selector
+ (void)setAnimationDuration:(NSTimeInterval)duration;              // 動畫的持續(xù)時間祠饺,秒為單位
+ (void)setAnimationDelay:(NSTimeInterval)delay;                    // 動畫延遲delay秒后再開始
+ (void)setAnimationStartDate:(NSDate *)startDate;                  // 動畫開始的時間,默認(rèn)為now
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve;              // 動畫的節(jié)奏控制  default = UIViewAnimationCurveEaseInOut
+ (void)setAnimationRepeatCount:(float)repeatCount;                 // 動畫的重復(fù)次數(shù)
+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses;    // 如果設(shè)置為YES汁政,代表動畫每次重復(fù)執(zhí)行的效果會跟上一次相反
+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState;  // 設(shè)置動畫開始時的狀態(tài)
/*
 如果是YES道偷,那么在開始和結(jié)束圖片視圖渲染一次并在動畫中創(chuàng)建幀;否則记劈,視圖將會在每一幀都渲染勺鸦。例如緩存,你不需要在視圖轉(zhuǎn)變中不停的更新目木,你只需要等到轉(zhuǎn)換完成再去更新視圖换途。
 1、開始一個動畫塊。
 2军拟、在容器視圖中設(shè)置轉(zhuǎn)換剃执。
 3、在容器視圖中移除子視圖懈息。
 4肾档、在容器視圖中添加子視圖。
 5辫继、結(jié)束動畫塊怒见。
 */

+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache;  // 設(shè)置視圖View的過渡效果,transition指定過渡類型姑宽,cache設(shè)置YES代表使用視圖緩存遣耍,性能較好

+ (void)setAnimationsEnabled:(BOOL)enabled;                         // 設(shè)置動畫是否可用
+ (BOOL)areAnimationsEnabled;                                       // 返回動畫效果是否開啟
+ (void)performWithoutAnimation:(void (^)(void))actionsWithoutAnimation NS_AVAILABLE_IOS(7_0);  // 先檢查動畫當(dāng)前是否啟用,然后禁止動畫低千,執(zhí)行block內(nèi)方法配阵,最后重新啟用動畫。它并不會阻塞局域CoreAnimation的動畫

+ (NSTimeInterval)inheritedAnimationDuration NS_AVAILABLE_IOS(9_0);

@end

UIView(UIViewAnimationWithBlocks)——動畫block

@interface UIView(UIViewAnimationWithBlocks)

// 下方三個是屬性動畫
/**
 *  動畫效果處理塊
 *
 *  @param duration   動畫時間
 *  @param delay      延遲時間
 *  @param options    動畫參數(shù)
 *  @param animations 動畫效果塊
 *  @param completion 完成效果塊
 */
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion;       // 一般的動畫

// 沒有延遲時間 沒有動畫參數(shù) options默認(rèn)為0
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion; // delay = 0.0, options = 0

// 動畫效果處理塊 delay= = 0.0示血,options = 0,completion = NULL
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL

/* Performs `animations` using a timing curve described by the motion of a spring. When `dampingRatio` is 1, the animation will smoothly decelerate to its final model values without oscillating. Damping ratios less than 1 will oscillate more and more before coming to a complete stop. You can use the initial spring velocity to specify how fast the object at the end of the simulated spring was moving before it was attached. It's a unit coordinate system, where 1 is defined as travelling the total animation distance in a second. So if you're changing an object's position by 200pt in this animation, and you want the animation to behave as if the object was moving at 100pt/s before the animation started, you'd pass 0.5. You'll typically want to pass 0 for the velocity. */
// Spring(彈簧)Animation的API比一般動畫多了兩個參數(shù) usingSpringWithDamping(范圍為0.0f~1.0f)救拉,數(shù)值越小彈簧的震動的效果越明顯     initialSpringVelocity表示初始速度难审,數(shù)值越大一開始移動越快
+ (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;      // 彈性動畫

// 過渡動畫效果塊
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion;     // 轉(zhuǎn)場動畫
/*
 [UIView transitionWithView:_redView
                 duration:2.0
                 options:UIViewAnimationOptionTransitionCurlDown
                 animations:^{
                     [_blackView removeFromSuperview];
                     [_redView addSubview:_blackView];
                 } completion:^(BOOL finished) {
                     _redView.backgroundColor = [UIColor brownColor];
     }];
 */

// 視圖之間切換的過渡動畫效果塊
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // toView added to fromView.superview, fromView removed from its superview


// 在一組視圖上執(zhí)行指定的系統(tǒng)動畫,并可以并行自定義動畫亿絮。其中parallelAnimations就是與系統(tǒng)動畫并行的自定義動畫
+ (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

UIView (UIViewKeyframeAnimations)——核心架構(gòu)動畫

@interface UIView (UIViewKeyframeAnimations)

/*
    關(guān)鍵幀動畫實例:
     [UIView animateKeyframesWithDuration:2.0delay:0options:UIViewKeyframeAnimationOptionRepeatanimations:^{
     
         _blackView.frame = CGRectMake(30, 30, 50, 50);
         [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0 animations:^{
         _redView.frame = CGRectMake(50, 50, 50, 50);
     }];
     
     } completion:^(BOOL finished) {
     
         _redView.frame= CGRectMake(50, 50, 100, 100);;
         _blackView.frame = CGRectMake(30, 30, 80, 80);
     
     }];
 */

// 為當(dāng)前視圖創(chuàng)建一個可以用于設(shè)置基本關(guān)鍵幀動畫的block對象
+ (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);
/**
 *  指定一個關(guān)鍵幀的單個幀的時間和動畫  iOS7后可用
 *
 *  @param frameStartTime 一個倍數(shù)從0~1告喊,假設(shè)一個動畫持續(xù)的時間是2秒,設(shè)置frameStartTime為0.5 那么后面設(shè)置的動畫將會在整體動畫執(zhí)行1秒后開始
 *  @param frameDuration  動畫持續(xù)時間
 *  @param animations     動畫效果塊
 */
+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTime relativeDuration:(double)frameDuration animations:(void (^)(void))animations NS_AVAILABLE_IOS(7_0); // start time and duration are values between 0.0 and 1.0 specifying time and duration relative to the overall time of the keyframe animation

@end

UIView (UIViewGestureRecognizers)——手勢識別

@interface UIView (UIViewGestureRecognizers)

@property(nullable, nonatomic,copy) NSArray<__kindof UIGestureRecognizer *> *gestureRecognizers;    // 訪問手勢集合

- (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer;       // 添加手勢
- (void)removeGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer;        // 移除手勢


- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;      // 通過返回值決定是否識別此手勢

@end

UIView (UIViewMotionEffects)——動作效果

@interface UIView (UIViewMotionEffects)

/*! Begins applying `effect` to the receiver. The effect's emitted keyPath/value pairs will be
 applied to the view's presentation layer.
 
 Animates the transition to the motion effect's values using the present UIView animation
 context. */


/*

 當(dāng)你打開裝有iOS7以上的iPhone主屏派昧,默認(rèn)的背景是一幅藍(lán)色的星空圖片黔姜。當(dāng)上下左右翻轉(zhuǎn)iPhone時,有趣的效果將會出現(xiàn)蒂萎,星空背景也會沿著各個方向發(fā)生位移秆吵,這與主屏上的各個App Icon形成了一種獨特的視差效果。
 //UIMotionEffect
 1. UIInterpolatingMotionEffect
 
 UIInterpolatingMotionEffect是UIMotionEffect的子類五慈,雖然擴(kuò)展也不復(fù)雜纳寂,提供的方法也很簡單,但在很多場景下可以比較直接和方便的滿足我們的需求泻拦。
 
 它有4個property:
 
 1.keyPath毙芜,左右翻轉(zhuǎn)屏幕將要影響到的屬性,比如center.x争拐。
 
 2.type(UIInterpolatingMotionEffectType類型)腋粥,觀察者視角,也就是屏幕傾斜的方式,目前區(qū)分水平和垂直兩種方式隘冲。
 
 3&4.minimumRelativeValue和maximumRelativeValue金赦,keyPath對應(yīng)的值的變化范圍,注意這個是id類型对嚼。min對應(yīng)最小的offset夹抗,max對應(yīng)最大的offset。
 
 UIInterpolatingMotionEffect * xEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
 xEffect.minimumRelativeValue =  [NSNumber numberWithFloat:-40.0];
 xEffect.maximumRelativeValue = [NSNumber numberWithFloat:40.0];
 [targetView addMotionEffect:xEffect];

 參考自http://www.cocoachina.com/ios/20150121/10967.html

*/

- (void)addMotionEffect:(UIMotionEffect *)effect NS_AVAILABLE_IOS(7_0);     // 添加一個UIMotionEffect

/*! Stops applying `effect` to the receiver. Any affected presentation values will animate to
 their post-removal values using the present UIView animation context. */
- (void)removeMotionEffect:(UIMotionEffect *)effect NS_AVAILABLE_IOS(7_0);      // 移除一個UIMotionEffect

@property (copy, nonatomic) NSArray<__kindof UIMotionEffect *> *motionEffects NS_AVAILABLE_IOS(7_0);    // 包含的UIMotionEffect

@end


//
// UIView Constraint-based Layout Support
//

typedef NS_ENUM(NSInteger, UILayoutConstraintAxis) {
    UILayoutConstraintAxisHorizontal = 0,
    UILayoutConstraintAxisVertical = 1
};

// Installing Constraints

/* A constraint is typically installed on the closest common ancestor of the views involved in the constraint.
 It is required that a constraint be installed on _a_ common ancestor of every view involved.  The numbers in a constraint are interpreted in the coordinate system of the view it is installed on.  A view is considered to be an ancestor of itself.
 */

UIView (UIConstraintBasedLayoutInstallingConstraints)——約束基于布局

@interface UIView (UIConstraintBasedLayoutInstallingConstraints)

@property(nonatomic,readonly) NSArray<__kindof NSLayoutConstraint *> *constraints NS_AVAILABLE_IOS(6_0);    // 視圖布局約束

- (void)addConstraint:(NSLayoutConstraint *)constraint; // 添加約束
- (void)addConstraints:(NSArray<__kindof NSLayoutConstraint *> *)constraints; // 添加一組約束
- (void)removeConstraint:(NSLayoutConstraint *)constraint; // 移除某個約束
- (void)removeConstraints:(NSArray<__kindof NSLayoutConstraint *> *)constraints; // 移除一組約束
@end

// Core Layout Methods

/* To render a window, the following passes will occur, if necessary.
 
 update constraints
 layout
 display
 
 Please see the conceptual documentation for a discussion of these methods.
 */

UIView (UIConstraintBasedLayoutCoreMethods)——核心布局方法

@interface UIView (UIConstraintBasedLayoutCoreMethods)
- (void)updateConstraintsIfNeeded; // 更新約束布局及其子布局
- (void)updateConstraints; // 更新約束布局
- (BOOL)needsUpdateConstraints;     // 返回約束布局是否需要更新纵竖,YES為是
- (void)setNeedsUpdateConstraints;      // 設(shè)置需要更新的約束布局
@end

// Compatibility and Adoption

UIView (UIConstraintBasedCompatibility)——布局兼容性

@interface UIView (UIConstraintBasedCompatibility)


@property(nonatomic) BOOL translatesAutoresizingMaskIntoConstraints; // 返回一個BOOL漠烧,判斷自動布局是否可以轉(zhuǎn)換約束布局


+ (BOOL)requiresConstraintBasedLayout;      // 返回View是否約束布局模式

@end

// Separation of Concerns

UIView (UIConstraintBasedLayoutLayering)——布局圖層

@interface UIView (UIConstraintBasedLayoutLayering)


- (CGRect)alignmentRectForFrame:(CGRect)frame;      // 返回視圖矩形對于指定視圖框架
- (CGRect)frameForAlignmentRect:(CGRect)alignmentRect;      // 返回框架對于指定視圖矩形


- (UIEdgeInsets)alignmentRectInsets;        // 返回自定義視圖框架

- (UIView *)viewForBaselineLayout NS_DEPRECATED_IOS(6_0, 9_0, "Override -viewForFirstBaselineLayout or -viewForLastBaselineLayout as appropriate, instead") __TVOS_PROHIBITED;      // 如果超出越是范圍,自動生成基線限制靡砌,以滿足視圖需求

/* -viewForFirstBaselineLayout is called by the constraints system when interpreting
 the firstBaseline attribute for a view.
 For complex custom UIView subclasses, override this method to return the text-based
 (i.e., UILabel or non-scrollable UITextView) descendant of the receiver whose first baseline
 is appropriate for alignment.
 UIView's implementation returns [self viewForLastBaselineLayout], so if the same
 descendant is appropriate for both first- and last-baseline layout you may override
 just -viewForLastBaselineLayout.
 */
@property(readonly,strong) UIView *viewForFirstBaselineLayout NS_AVAILABLE_IOS(9_0);

/* -viewForLastBaselineLayout is called by the constraints system when interpreting
 the lastBaseline attribute for a view.
 For complex custom UIView subclasses, override this method to return the text-based
 (i.e., UILabel or non-scrollable UITextView) descendant of the receiver whose last baseline
 is appropriate for alignment.
 UIView's implementation returns self.
 */
@property(readonly,strong) UIView *viewForLastBaselineLayout NS_AVAILABLE_IOS(9_0);

/* Override this method to tell the layout system that there is something it doesn't natively understand in this view, and this is how large it intrinsically is.  A typical example would be a single line text field.  The layout system does not understand text - it must just be told that there's something in the view, and that that something will take a certain amount of space if not clipped.
 
 In response, UIKit will set up constraints that specify (1) that the opaque content should not be compressed or clipped, (2) that the view prefers to hug tightly to its content.
 
 A user of a view may need to specify the priority of these constraints.  For example, by default, a push button
 -strongly wants to hug its content in the vertical direction (buttons really ought to be their natural height)
 -weakly hugs its content horizontally (extra side padding between the title and the edge of the bezel is acceptable)
 -strongly resists compressing or clipping content in both directions.
 
 However, you might have a case where you'd prefer to show all the available buttons with truncated text rather than losing some of the buttons. The truncation might only happen in portrait orientation but not in landscape, for example. In that case you'd want to setContentCompressionResistancePriority:forAxis: to (say) UILayoutPriorityDefaultLow for the horizontal axis.
 
 The default 'strong' and 'weak' priorities referred to above are UILayoutPriorityDefaultHigh and UILayoutPriorityDefaultLow.
 
 Note that not all views have an intrinsicContentSize.  UIView's default implementation is to return (UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric).  The _intrinsic_ content size is concerned only with data that is in the view itself, not in other views. Remember that you can also set constant width or height constraints on any view, and you don't need to override instrinsicContentSize if these dimensions won't be changing with changing view content.
 */
UIKIT_EXTERN const CGFloat UIViewNoIntrinsicMetric NS_AVAILABLE_IOS(6_0); // -1
- (CGSize)intrinsicContentSize;     // 返回view的自然尺寸
- (void)invalidateIntrinsicContentSize; // 使內(nèi)容尺寸無效化

- (UILayoutPriority)contentHuggingPriorityForAxis:(UILayoutConstraintAxis)axis;     // 返回放大的視圖布局的軸線
- (void)setContentHuggingPriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis;      // 設(shè)置放大的視圖布局的軸線

- (UILayoutPriority)contentCompressionResistancePriorityForAxis:(UILayoutConstraintAxis)axis;       // 返回縮小的視圖布局的軸線
/*
 axis:布局約束
 枚舉值:
 UILayoutConstraintAxisHorizontal    //水平
 UILayoutConstraintAxisVertical      //垂直
 返回值:小數(shù)
 */
- (void)setContentCompressionResistancePriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis;    // 設(shè)置縮小的視圖布局的軸線
@end

// Size To Fit

UIKIT_EXTERN const CGSize UILayoutFittingCompressedSize NS_AVAILABLE_IOS(6_0);
UIKIT_EXTERN const CGSize UILayoutFittingExpandedSize NS_AVAILABLE_IOS(6_0);

UIView (UIConstraintBasedLayoutFittingSize)——約束基于布局適應(yīng)尺寸

@interface UIView (UIConstraintBasedLayoutFittingSize)

- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize; // 返回最合適的尺寸
- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority;   // 滿足約束視圖布局的大小
@end

UIView (UILayoutGuideSupport)——布局指南支持

@interface UIView (UILayoutGuideSupport)

/* UILayoutGuide objects owned by the receiver.
 */
@property(nonatomic,readonly,copy) NSArray<__kindof UILayoutGuide *> *layoutGuides NS_AVAILABLE_IOS(9_0);

/* Adds layoutGuide to the receiver, passing the receiver in -setOwningView: to layoutGuide.
 */
- (void)addLayoutGuide:(UILayoutGuide *)layoutGuide NS_AVAILABLE_IOS(9_0);

/* Removes layoutGuide from the receiver, passing nil in -setOwningView: to layoutGuide.
 */
- (void)removeLayoutGuide:(UILayoutGuide *)layoutGuide NS_AVAILABLE_IOS(9_0);
@end

@class NSLayoutXAxisAnchor,NSLayoutYAxisAnchor,NSLayoutDimension;
@interface UIView (UIViewLayoutConstraintCreation)
/* Constraint creation conveniences. See NSLayoutAnchor.h for details.
 */
@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

// Debugging

/* Everything in this section should be used in debugging only, never in shipping code.  These methods may not exist in the future - no promises.
 */

UIView (UIConstraintBasedLayoutDebugging)——布局Debug

@interface UIView (UIConstraintBasedLayoutDebugging)


- (NSArray<__kindof NSLayoutConstraint *> *)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis;     // 返回影響視圖布局限制的軸線


- (BOOL)hasAmbiguousLayout;     // 返回視圖布局約束是否影響指定視圖已脓,主要用于調(diào)試約束布局,結(jié)合exerciseAmbiguityInLayout
- (void)exerciseAmbiguityInLayout;      // 隨機改變不同效值布局視圖通殃,主要用于調(diào)試基于約束布局的視圖
@end

UIView (UIStateRestoration)——狀態(tài)復(fù)位

@interface UIView (UIStateRestoration)
@property (nullable, nonatomic, copy) NSString *restorationIdentifier;      // 該標(biāo)識符決定該視圖是否支持恢復(fù)狀態(tài)度液,其實也只是個標(biāo)識符而已
- (void) encodeRestorableStateWithCoder:(NSCoder *)coder;       // 保存視圖狀態(tài)相關(guān)信息
- (void) decodeRestorableStateWithCoder:(NSCoder *)coder;       // 恢復(fù)和保持視圖狀態(tài)相關(guān)信息
@end

UIView (UISnapshotting)

@interface UIView (UISnapshotting)

- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates;      // 返回一個基于當(dāng)前視圖的內(nèi)容快照視圖
- (UIView *)resizableSnapshotViewFromRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates withCapInsets:(UIEdgeInsets)capInsets;  // 返回一個基于當(dāng)前視圖的特定內(nèi)容的快照視圖,拉伸插圖

- (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates;     // 利用View層次結(jié)構(gòu)病將其繪制到當(dāng)前的上下文中
@end

NS_ASSUME_NONNULL_END

記錄文件已經(jīng)上傳至git:

--> 傳送門:SH_The-record-of-the-API

有問題歡迎指正以及相互探討 —— CoderSun

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末画舌,一起剝皮案震驚了整個濱河市堕担,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌曲聂,老刑警劉巖霹购,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異朋腋,居然都是意外死亡齐疙,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進(jìn)店門旭咽,熙熙樓的掌柜王于貴愁眉苦臉地迎上來贞奋,“玉大人,你說我怎么就攤上這事穷绵〗嗡” “怎么了?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵请垛,是天一觀的道長催训。 經(jīng)常有香客問我,道長宗收,這世上最難降的妖魔是什么漫拭? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮混稽,結(jié)果婚禮上采驻,老公的妹妹穿的比我還像新娘审胚。我一直安慰自己,他們只是感情好礼旅,可當(dāng)我...
    茶點故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布膳叨。 她就那樣靜靜地躺著,像睡著了一般痘系。 火紅的嫁衣襯著肌膚如雪菲嘴。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天汰翠,我揣著相機與錄音龄坪,去河邊找鬼。 笑死复唤,一個胖子當(dāng)著我的面吹牛健田,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播佛纫,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼妓局,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了呈宇?” 一聲冷哼從身側(cè)響起好爬,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎攒盈,沒想到半個月后抵拘,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡型豁,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了尚蝌。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片迎变。...
    茶點故事閱讀 39,902評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖飘言,靈堂內(nèi)的尸體忽然破棺而出衣形,到底是詐尸還是另有隱情,我是刑警寧澤姿鸿,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布谆吴,位于F島的核電站,受9級特大地震影響苛预,放射性物質(zhì)發(fā)生泄漏句狼。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一热某、第九天 我趴在偏房一處隱蔽的房頂上張望腻菇。 院中可真熱鬧胳螟,春花似錦、人聲如沸筹吐。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽丘薛。三九已至嘉竟,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間洋侨,已是汗流浹背舍扰。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留凰兑,地道東北人妥粟。 一個月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像吏够,于是被迫代替她去往敵國和親勾给。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,843評論 2 354

推薦閱讀更多精彩內(nèi)容

  • 在iOS中隨處都可以看到絢麗的動畫效果锅知,實現(xiàn)這些動畫的過程并不復(fù)雜播急,今天將帶大家一窺ios動畫全貌。在這里你可以看...
    每天刷兩次牙閱讀 8,489評論 6 30
  • 在iOS中隨處都可以看到絢麗的動畫效果售睹,實現(xiàn)這些動畫的過程并不復(fù)雜桩警,今天將帶大家一窺iOS動畫全貌。在這里你可以看...
    F麥子閱讀 5,111評論 5 13
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫昌妹、插件捶枢、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,103評論 4 62
  • 蒙版作用:用黑白灰的不同色階,來對所蒙版的圖形進(jìn)行不同程度的遮擋飞崖。這里的黑白灰只 代表遮擋度...
    慌張女士閱讀 778評論 1 4
  • 遇見是為了日后的 想念固歪,而每一次付出都在 試圖著推遲別離蒜鸡。
    風(fēng)清越朗閱讀 184評論 3 2