1.繼承鏈:UIresponder:NSObjecthtml
2.經過使用 addGestureRecognizer:方法能夠爲視圖添加手勢
spring
3.下面的屬性均可以用來用於動畫api
@property transform
iview
4.子視圖通常用來進行覆蓋的方法:
(1)initWithFrame:通常用來初始化一個UI控件,位置和大小
(2)initWithCoder:使用這個方法來載入你的nib file文件到interface builder中
(3)layerClass:不知道怎麼翻譯 Implement this method only if you want your view to use a different Core Animation layer for its backing store.
(4)drawRect:通常用來繪製你的自定義視圖內容
(5)drawRect:forViewPrintFormatter:當你想在你的自定義視圖中定義不一樣的視圖內容能夠重載這個方法
(6)requiresConstraintBasedLayout:若是你想要正確的約束你的視圖可使用這個方法
(7)updateConstraints:若是你的視圖和你的子視圖要建立有一個自定義約束可使用這個方法,應該是用來更新約束的把
(8)alignmentRectForFrame:
, frameForAlignmentRect:實現讓你的視圖如何和其餘視圖對齊
(9)sizeThatFits:
- Implement this method if you want your view to have a different default size than it normally would during resizing operations.
(10)layoutSubviews:使用這個方法來使你的視圖更加精確的佈局而不使用那些約束
(11)didAddSubview:
, willRemoveSubview:能夠用來更加或者刪除一些視圖
(12)willMoveToSuperview:
, didMoveToSuperview
- Implement these methods as needed to track the movement of the current view in your view hierarchy.
(13)willMoveToWindow:
, didMoveToWindow
- Implement these methods as needed to track the movement of your view to a different window.
(14)touchesBegan:withEvent:
, touchesMoved:withEvent:
, touchesEnded:withEvent:
, touchesCancelled:withEvent:當發生觸碰事件的時候可使用這些方法
(15)gestureRecognizerShouldBegin:發生觸碰時間或者其餘的手勢時間的時候可使用這個方法
5.UIview的方法大全:
/** 獲取到事件中點擊的視圖用來判斷當前點擊 */
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
/** 獲取事件event中的觸發視圖*/
UIView *hitView = [superhitTest:point withEvent:event];
/** 判斷是否當前視圖 */
if (hitView ==self) {
returnnil;
} else {
return hitView;
}
}
/** 判斷是不是當前視圖觸發的事件 */
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
return [superpointInside:point withEvent:event];
}
/** 將一個座標點轉換成指定view的座標 */
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view{
return [superconvertPoint:point toView:view];
}
/** 將一個座標點轉換成當前view的座標 */
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view{
return [superconvertPoint:point fromView:view];
}
/** 將一個CGRect轉換成指定view的CGRect */
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view{
return [superconvertRect:rect toView:view];
}
/** 講一個CGRect轉換成當前view的CGRect */
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view{
return [superconvertRect:rect fromView:view];
}
/** 獲取適合label內容的CGSize */
- (CGSize)sizeThatFits:(CGSize)size{
return [supersizeThatFits:size];
}
/** 自動設置適合內容的CGSize */
- (void)sizeToFit{
[supersizeToFit];
}
/** 從父視圖中移除當前視圖 */
- (void)removeFromSuperview{
[superremoveFromSuperview];
}
/** 在index層插入一個視圖 */
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index{
[superinsertSubview:view atIndex:index];
}
/** 交換兩個視圖的圖層 */
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2{
[superexchangeSubviewAtIndex:index1 withSubviewAtIndex:index2];
}
/** 加入一個視圖在最上一層 */
- (void)addSubview:(UIView *)view{
[superaddSubview:view];
}
/** 在siblingSubview視圖下面插入一個視圖 */
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview{
[superinsertSubview:view belowSubview:siblingSubview];
}
/** 在siblingSubview視圖上面插入一個視圖 */
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview{
[superinsertSubview:view aboveSubview:siblingSubview];
}
/** 將一個視圖放到最上一層 */
- (void)bringSubviewToFront:(UIView *)view{
[superbringSubviewToFront:view];
}
/** 將一個視圖推送到最下層 */
- (void)sendSubviewToBack:(UIView *)view{
[supersendSubviewToBack:view];
}
/** 添加子視圖時調用 */
- (void)didAddSubview:(UIView *)subview;{
[superdidAddSubview:subview];
NSLog(@"添加子視圖");
}
/** 將要移除子視圖時調用 */
- (void)willRemoveSubview:(UIView *)subview{
[superwillRemoveSubview:subview];
NSLog(@"移除子視圖");
}
/** 父視圖將要發生更改時調用 */
- (void)willMoveToSuperview:(UIView *)newSuperview{
[superwillMoveToSuperview:newSuperview];
NSLog(@"父視圖將要發生更改");
}
/** 父視圖更改時調用 */
- (void)didMoveToSuperview{
[superdidMoveToSuperview];
NSLog(@"父視圖發生更改");
}
/** 視圖或其超視圖將要展現到窗口調用 */
- (void)willMoveToWindow:(UIWindow *)newWindow{
[superwillMoveToWindow:newWindow];
NSLog(@"視圖展現到窗口");
}
/** 視圖或其超視圖展現到窗口調用 */
- (void)didMoveToWindow{
[superdidMoveToSuperview];
NSLog(@"視圖或其超視圖展現到窗口");
}
/** 判斷當前視圖是不是指定視圖或者其子視圖 */
- (BOOL)isDescendantOfView:(UIView *)view{
return [superisDescendantOfView:view];
}
/** 獲取當前視圖內指定tag值的視圖 */
- (UIView *)viewWithTag:(NSInteger)tag{
return [superviewWithTag:tag];
}
/** 在圖層繪製時調用的方法 */
- (void)setNeedsLayout{
}
- (void)layoutIfNeeded{
}
/** 當視圖上的圖層發生改變時調用 */
- (void)layoutSubviews{
}
/** 發生自動佈局時調用 */
- (void)layoutMarginsDidChange{
}
/** 繪製圖層layer時調用 */
- (void)drawRect:(CGRect)rect{
}
/** 重繪圖層 */
- (void)setNeedsDisplay{
}
/** 重繪圖層指定範圍 */
- (void)setNeedsDisplayInRect:(CGRect)rect{
}
/** tintColor 是一種有拋光效果的設置視圖顏色 */
/** tintColor改變時調用 */
- (void)tintColorDidChange{
}
#pragma mark - 動畫相關
/** 開啓動畫塊 animationID動畫標示 context參數 */
+ (void)beginAnimations:(NSString *)animationID context:(void *)context{
[superbeginAnimations:animationID context:context];
}
/** 提交動畫塊動畫開始執行 */
+ (void)commitAnimations{
[supercommitAnimations];
}
/** 設置動畫代理 */
+ (void)setAnimationDelegate:(id)delegate{
[supersetAnimationDelegate:delegate];
}
/** 當動畫開始時發送一個消息給動畫代理 */
+ (void)setAnimationWillStartSelector:(SEL)selector{
[supersetAnimationWillStartSelector:selector];
/** 動畫代理執行selector方法 */
}
/** 當動畫結束時發送一個消息給動畫代理 */
+ (void)setAnimationDidStopSelector:(SEL)selector{
[supersetAnimationDidStopSelector:selector];
/** 動畫代理執行selector方法 */
}
/** 設置動畫時長默認0.2s */
+ (void)setAnimationDuration:(NSTimeInterval)duration{
[supersetAnimationDuration:duration];
}
/** 設置動畫執行延遲時長默認0s */
+ (void)setAnimationDelay:(NSTimeInterval)delay{
[supersetAnimationDelay:delay];
}
/** 設置動畫開始時間NSDate */
+ (void)setAnimationStartDate:(NSDate *)startDate{
[supersetAnimationStartDate:startDate];
}
/** 設置動畫的曲線方式(就是動畫的整體變化的時間曲線:開始快最後慢,開始慢最後快,最後慢,均勻線性)。
curve參數以下:
typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {
UIViewAnimationCurveEaseInOut, // slow at beginning and end
UIViewAnimationCurveEaseIn, // slow at beginning
UIViewAnimationCurveEaseOut, // slow at end
UIViewAnimationCurveLinear
};
*/
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve{
[supersetAnimationCurve:curve];
}
/** 設置動畫重複次數 */
+ (void)setAnimationRepeatCount:(float)repeatCount{
[supersetAnimationRepeatCount:repeatCount];
}
/**
設置動畫是否作一次反向的執行。
若是設置爲YES:動畫將執行:動畫初始狀態》動畫》動畫完成狀態》動畫》動畫初始狀態。
若是設置爲NO:默認值
*/
+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses{
[supersetAnimationRepeatAutoreverses:repeatAutoreverses];
}
/** 設置動畫開始時狀態
當YES時:當上一次動畫正在執行中,那麼當下一個動畫開始時,上一次動畫的當前狀態將成爲下一次動畫的開始狀態。
當NO時:當上一個動畫正在執行中,那麼當下一個動畫開始時,上一次動畫須要先恢復到完成時的狀態,而後在開始執行下一次動畫。
*/
+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState{
}
/** 添加動畫到視圖view上 transition動畫樣式 cache爲YES時高效 但動畫執行過程當中不能更新UI爲NO時每一幀均可以從新繪製 能夠實時更新UI */
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView*)view cache:(BOOL)cache{
}
/** 是否支持動畫默認YES */
+ (void)setAnimationsEnabled:(BOOL)enabled{
}
/** 返回動畫效果是否被禁用 */
+ (BOOL)areAnimationsEnabled{
return [superareAnimationsEnabled];
}
/** 強制一些動做不使用動畫我也不懂 測出來再補上 */
+ (void)performWithoutAnimation:(void (^)(void))actionsWithoutAnimation{
}
#pragma mark - 動畫Block塊
/**
duration 執行時長
delay 延遲時長
options 動畫執行曲線
animations 動畫動做Block
completion 動畫執行完畢後執行的Block
*/
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion {
}
/**
duration 執行時長
animations 動畫動做Block
completion 動畫執行完畢後執行的Block
*/
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion {
}
/**
duration 執行時長
animations 動畫動做Block
*/
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations {
}
/**
SpringAnimation動畫乾淨 快速
usingSpringWithDamping 0~1 彈簧效果越小彈簧效果越明顯
initialSpringVelocity 初始速度初始速度取值較高而時間較短時 也會出現彈簧效果
*/
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion {
}
/**
過場動畫
duration 動畫時長
view 進行轉場動畫的視圖
options 專場動畫類型
animations 執行動畫
completion 動畫結束後調用的Block
*/
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void(^)(BOOL finished))completion {
}
/**
過場動畫
[fromView.superview addSubview:toView];
[fromView.superview removeFromSuperview];
*/
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion {
}
/**
在一組視圖上執行指定的系統動畫,並能夠並行自定義的動畫
parallelAnimations就是與系統動畫並行的自定義動畫
*/
+ (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray *)views options:(UIViewAnimationOptions)options animations:(void (^)(void))parallelAnimations completion:(void (^)(BOOL finished))completion {
}
#pragma mark - UIViewKeyframeAnimations
/**
關鍵幀動畫
duration 動畫時長
delay 動畫延遲
options 動畫效果選項
animations 動畫執行代碼
completion 動畫結束執行代碼
*/
+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void(^)(void))animations completion:(void (^)(BOOL finished))completion {
}
/**
frameStartTime 動畫相對開始時間
frameDuration 動畫相對持續時間
自身會根據動畫總持續時長自動匹配其運行時長
*/
+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTime relativeDuration:(double)frameDuration animations:(void (^)(void))animations {
}
#pragma mark - 手勢
/** 添加手勢 */
- (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer {
}
/** 移除手勢 */
- (void)removeGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer {
}
/** 是否執行該手勢 */
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
returnYES;
}
/** 添加運動擬真效果 */
/** UIMotionEffect 運動擬真效果類物理效果 */
- (void)addMotionEffect:(UIMotionEffect *)effect {
}
/** 移除運動擬真效果 */
- (void)removeMotionEffect:(UIMotionEffect *)effect {
}
#pragma mark - 約束自動佈局
/** 只知道是自動佈局相關可是具體效果 未知查不到 測不出==! */
- (NSArray *)constraints {
return [superconstraints];
}
/** 添加約束須要先開啓自動佈局 */
- (void)addConstraint:(NSLayoutConstraint *)constraint {
}
/** 添加約束 */
- (void)addConstraints:(NSArray *)constraints {
}
/** 移除約束 */
- (void)removeConstraint:(NSLayoutConstraint *)constraint {
}
/** 移除約束 */
- (void)removeConstraints:(NSArray *)constraints {
}
/** 更新視圖和其子視圖的約束 */
- (void)updateConstraintsIfNeeded {
}
/** 更新視圖和其子視圖的約束 */
- (void)updateConstraints {
}
/** 是否更新視圖的約束 */
- (BOOL)needsUpdateConstraints {
return [superneedsUpdateConstraints];
}
/** 設置視圖的約束須要更新 */
- (void)setNeedsUpdateConstraints {
}
/** 是否關閉自動佈局 */
- (BOOL)translatesAutoresizingMaskIntoConstraints {
return [supertranslatesAutoresizingMaskIntoConstraints];
}
/** 是否關閉自動佈局 */
- (void)setTranslatesAutoresizingMaskIntoConstraints:(BOOL)flag {
}
/** 是否支持自動佈局 */
+ (BOOL)requiresConstraintBasedLayout {
return [superrequiresConstraintBasedLayout];
}
/** 返回給定框架的視圖的對齊矩陣 */
- (CGRect)alignmentRectForFrame:(CGRect)frame {
return [superalignmentRectForFrame:frame];
}
/** 返回給定對齊矩形的視圖的frame */
- (CGRect)frameForAlignmentRect:(CGRect)alignmentRect {
return [superframeForAlignmentRect:alignmentRect];
}
/** 對當前View設置用來佈局的矩形設置偏移 */
- (UIEdgeInsets)alignmentRectInsets {
return [superalignmentRectInsets];
}
/** 默認返回當前視圖的底部做爲baseline。咱們能夠重寫上述方法,但必須返回的是當前視圖中的子視圖 */
- (UIView *)viewForBaselineLayout {
return [superviewForBaselineLayout];
}
/** 經過重寫intrinsicContentSize能夠設置當前視圖顯示特定內容時的大小 */
- (CGSize)intrinsicContentSize {
CGSize size = [superintrinsicContentSize];
if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
size.width +=4.0f;
} else {
size.width +=40.0f;
}
if (self.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact) {
size.height +=4.0;
} else {
size.height +=40.0;
}
return size;
}
/** 視圖根據內部內容設置Size */
- (void)invalidateIntrinsicContentSize {
[superinvalidateIntrinsicContentSize];
}
- (UILayoutPriority)contentHuggingPriorityForAxis:(UILayoutConstraintAxis)axis {
return [supercontentHuggingPriorityForAxis:axis];
}
/** 使其在「內容大小」的基礎上不能繼續變大 */
- (void)setContentHuggingPriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis {
}
- (UILayoutPriority)contentCompressionResistancePriorityForAxis:(UILayoutConstraintAxis)axis {
return [supercontentCompressionResistancePriorityForAxis:axis];
}
/** 使其在在其「內容大小」的基礎上不能繼續變小 */
- (void)setContentCompressionResistancePriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis {
}
/** 動態計算控件的Size targetSize可傳參數:UILayoutFittingCompressedSize最小狀況下可能的Size UILayoutFittingExpandedSize最大狀況下可能的Size */
- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize {
return [supersystemLayoutSizeFittingSize:targetSize];
}
/** 動態計算控件的Size UILayoutPriority優先級
horizontalFittingPriority 水平約束優先級
verticalFittingPriority 垂直約束優先級 */
- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority {
return[supersystemLayoutSizeFittingSize:targetSizewithHorizontalFittingPriority:horizontalFittingPriorityverticalFittingPriority:verticalFittingPriority];
}
/** 約束檢查爲何這個View 這樣顯返回值 約束條件 */
- (NSArray *)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis {
return [superconstraintsAffectingLayoutForAxis:axis];
}
/** 判斷當前的自動佈局約束是否還有其餘知足約束的條件 */
- (BOOL)hasAmbiguousLayout {
return [superhasAmbiguousLayout];
}
/** 隨機實現一個知足約束的條件 */
- (void)exerciseAmbiguityInLayout {
}
#pragma mark - NSCoder
/** 歸檔時編碼 */
- (void) encodeRestorableStateWithCoder:(NSCoder *)coder {
}
/** 反歸檔時解碼 */
- (void) decodeRestorableStateWithCoder:(NSCoder *)coder {
}
/** 複製一個複合視圖
afterUpdates 是否視圖展現時才生成視圖
No 會當即生成快照,並不會調用從新設置顏色的方法無色
YES 當調用這個視圖時生成
*/
- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates {
return [supersnapshotViewAfterScreenUpdates:afterUpdates];
}
/** 複製一個指定範圍偏移量的複合視圖 */
- (UIView *)resizableSnapshotViewFromRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates withCapInsets:(UIEdgeInsets)capInsets {
return[superresizableSnapshotViewFromRect:rectafterScreenUpdates:YESwithCapInsets:capInsets];
}
/** 將指定範圍的視圖繪製到圖形上下文中 */
- (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates {
return [superdrawViewHierarchyInRect:rect afterScreenUpdates:afterUpdates];
}
6.UIview的屬性:
(2)hidden:布爾類型,是否隱藏視圖
(3)alpha:cgfloat類型,設置視圖的透明度,0.0-1.0
(4)opaque:布爾類型,是否爲不透明
(5)clipsToBounds,布爾類型,是否限制子視圖只能在視圖中顯示
(6)clearsContextBeforeDrawing:布爾類型,是否在繪製以前自動清除界限bounds
(7)maskView:uiview類型,經過這個視圖的透明度來遮蓋另外一個視圖的內容
(8)+ (Class)layerClass:能夠經過這個方法返回一個不一樣類型的視圖圖層
7.和事件接觸有關的行爲:
(1)userInteractionEnabled:布爾類型,是否容許用戶和視圖進行交互
(2)multipleTouchEnabled:布爾類型,是否容許視圖可以響應多重接觸事件
(3)exclusiveTouch:布爾類型,是否讓接受者惟一的響應接觸事件
(4)- (BOOL)isDescendantOfView:(UIView *)view:返回一個布爾類型,確認這個視圖是不是一個視圖的子視圖
(5)@property(nonatomic) UIViewAutoresizing autoresizingMask,當父視圖的邊界改變的時候子視圖也得從新調整大小
(6)@property(nonatomic) BOOL autoresizesSubviews:是否容許子視圖邊界自動調整
(7)@property(nonatomic) UIViewContentMode contentMode:當邊界改變時該使用哪一種方式調整內容
(8) - (void)sizeToFit:視圖的大小隨視圖內容的改變而調整
(9)setNeedsLayout:消除舊的視圖佈局,下一個更新循環到來的時候更新視圖佈局
(10)- (void)layoutIfNeeded:快速進行自動佈局子視圖
(11) + (BOOL)requiresConstraintBasedLayout:布爾類型,指定接收者是否以約束爲基礎添加系統的佈局,就是說若是你的約束不完整可使用這個來補全
(12)@property(nonatomic) BOOL translatesAutoresizingMaskIntoConstraints若是爲yes,系統就會建立一系列的約束If this property’s value is YES
, the system creates a set of constraints that duplicate the behavior specified by the view’s autoresizing mask.
8.只讀屬性:
(1)@property(readonly, strong) NSLayoutYAxisAnchor *bottomAnchor:Use this anchor to create constraints with the view’s bottom edge. You can combine this anchor only with other NSLayoutYAxisAnchor
anchors. For more information, see NSLayoutAnchor Class Reference.
(2)@property(readonly, strong) NSLayoutXAxisAnchor *centerXAnchor:可使用這個錨點建立視圖水平中心的約束
(3)@property(readonly, strong) NSLayoutYAxisAnchor *centerYAnchor:可使用這個錨點建立垂直中心的約束
(4)@property(readonly, strong) NSLayoutYAxisAnchor *firstBaselineAnchor:For views with multiple lines of text, this anchor represents the baseline of the top row of text. Use this anchor to create constraints with this baseline.
(5)@property(readonly, strong) NSLayoutDimension *heightAnchor:可使用這個錨點建立視圖高度的約束
(6)@property(readonly, strong) NSLayoutYAxisAnchor *lastBaselineAnchor:For views with multiple lines of text, this anchor represents the baseline of the bottom row of text. Use this anchor to create constraints with this baseline
(7)@property(readonly, strong) NSLayoutXAxisAnchor *leadingAnchor可使用這個錨點建立對齊邊緣
(8)@property(readonly, strong) NSLayoutXAxisAnchor *leftAnchor:可使用這個錨點建立左邊緣的約束
(9)@property(readonly, strong) NSLayoutXAxisAnchor *rightAnchor:建立右邊緣的約束
(10)@property(readonly, strong) NSLayoutYAxisAnchor *topAnchor:建立頂邊緣的約束
(11)@property(readonly, strong) NSLayoutXAxisAnchor *trailingAnchor:建立視圖尾部的約束
(12)@property(readonly, strong) NSLayoutDimension *widthAnchor:建立視圖寬度的約束
9.管理視圖的約束:
(1)@property(nonatomic, readonly) NSArray <__kindof NSLayoutConstraint *> *constraints:讀取視圖的約束
(2)- (void)addConstraint:(NSLayoutConstraint *)constraint:爲視圖或者子視圖添加一個約束
(3)- (void)addConstraints:(NSArray<__kindofNSLayoutConstraint *> *)constraints:爲視圖或者子視圖添加約束組
(4)- (void)removeConstraint:(NSLayoutConstraint *)constraint:刪除約束
(5)- (void)removeConstraints:(NSArray<__kindofNSLayoutConstraint *> *)constraints刪除約束組
10.使用佈局指引
(1)- (void)addLayoutGuide:(UILayoutGuide *)layoutGuide添加布局指引
(2)@property(nonatomic, readonly, copy) NSArray <__kindof UILayoutGuide *> *layoutGuides:這個視圖的佈局指引數組,只讀
(3)@property(readonly, strong) UILayoutGuide *layoutMarginsGuide:爲視圖邊緣添加一個邊緣約束,只讀
(4)@property(nonatomic, readonly, strong) UILayoutGuide *readableContentGuide:一個可讀區域的寬
(5)- (void)removeLayoutGuide:(UILayoutGuide *)layoutGuide:刪除佈局指引
11.自動佈局:
(1)- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize:參考該視圖全部的約束和子視圖來決定最好的大小
(2)- (void)invalidateIntrinsicContentSize:Invalidates the view’s intrinsic content size.
(3)- (UILayoutPriority)contentCompressionResistancePriorityForAxis:(UILayoutConstraintAxis)axis:
The constraint-based layout system uses these priorities when determining the best layout for views that are encountering constraints that would require them to be smaller than their intrinsic size.
(4)- (void)setContentHuggingPriority:(UILayoutPriority)priority
forAxis:(UILayoutConstraintAxis)axis :
Sets the priority with which a view resists being made larger than its intrinsic size.
12.自動佈局對齊視圖:
(1)- (CGRect)alignmentRectForFrame:(CGRect)frame: Returns the view’s alignment rectangle for a given frame.
alignmentRect : Returns the view’s frame for a given alignment rectangle
:返回一個視圖用來知足最後的基線約束。
13.觸發自動約束
(1)- (BOOL)needsUpdateConstraints :布爾值類型,決定是否須要要更新視圖的約束
(2)- (void)setNeedsUpdateConstraints : 方法,控制視圖約束是否須要更新
(3)- (void)updateConstraints :爲視圖更新約束
(4)- (void)updateConstraintsIfNeeded : 不管佈局何時被觸發,系統會調用這個方法來更新當前視圖的約束
14.調試自動佈局
(1)- (BOOL)hasAmbiguousLayout : yes的話就不徹底指定視圖的位置
(2)- (void)exerciseAmbiguityInLayout : 這個方法隨機的改變視圖的frame經過一個不肯定的值
(3)@property(nonatomic) UISemanticContentAttribute semanticContentAttribute : 一般用來決定視圖是否可以快速滑動
(4)+ (UIUserInterfaceLayoutDirection)userInterfaceLayoutDirectionForSemanticContentAttribute:(UISemanticContentAttribute)attribute : 當視圖有子視圖的時候可使用這個方法來決定子視圖是否須要快速翻動
15.配置內容邊緣
(1)@property(nonatomic) UIEdgeInsets layoutMargins :Use this property to specify the desired amount of space (measured in points) between the edge of the view and any subviews. Auto layout uses your margins as a cue for placing content
(2)@property(nonatomic) BOOL preservesSuperviewLayoutMargins : 當這個屬性的值爲yes 的時候,進行佈局的時候也須要考慮到父視圖的邊緣
(3)- (void)layoutMarginsDidChange : 通知視圖佈局邊緣發生了改變
16.繪製和更新視圖
(1)- (void)drawRect:(CGRect)rect : 當你想繪製本身的視圖內容時應該重載這個方法‘
(2)- (void)setNeedsDisplay : 當你的視圖內容須要重畫的時候能夠重載這個方法,可是這個方法不會當即更新,只有在下一輪的循環到來的時候也就是舊的點再也不用的時候纔會更新
(3)- (void)setNeedsDisplayInRect:(CGRect)invalidRect : 爲接受者指定的矩形區域進行重畫,當你的視圖內容有某一部分須要重畫的時候能夠重載這個方法
(4)@property(nonatomic) CGFloat contentScaleFactor :就是用這個屬性來改變視圖的大小,例如視圖爲50*50 , 這個屬性值爲2.0 , 最後獲得的視圖爲100*100
(5)- (void)tintColorDidChange :當tintcolor屬性發生改變的時候就會觸發這個方法
17.格式的打印視圖內容
(1)- (UIViewPrintFormatter *)viewPrintFormatter : 當初始化一個打印任務時,能夠爲你的視圖調用這個方法獲取合適的視圖打印格式
(2)- (void)drawRect:(CGRect)area
forViewPrintFormatter:(UIViewPrintFormatter *)formatter :
若是你想要一個視圖的印刷內容出現不一樣於其顯示內容可使用這個方法
18.管理手勢識別器
(1)- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer : 爲視圖添加一個手勢識別器
(2)- (void)removeGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer : 從視圖中移除有一個手勢識別器
(3)@property(nonatomic, copy) NSArray <__kindof UIGestureRecognizer *> *gestureRecognizers : 當前在視圖中的視圖識別器組成的數組
(4)- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer :若是爲yes的時候該手勢就應該一直跟蹤接觸事件
19.動畫視圖和塊對象
(1)+ (void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
duration |
The total duration of the animations, measured in seconds. If you specify a negative value or |
delay |
The amount of time (measured in seconds) to wait before beginning the animations. Specify a value of |
options |
A mask of options indicating how you want to perform the animations. For a list of valid constants, see |
animations |
A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be |
completion |
A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be |
duration
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
duration |
The total duration of the animations, measured in seconds. If you specify a negative value or |
animations |
A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be |
completion |
A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be |
duration
animations:(void (^)(void))animations
duration |
The total duration of the animations, measured in seconds. If you specify a negative value or |
animations |
A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be |
view
duration:(NSTimeInterval)duration
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
view |
The container view that performs the transition. |
duration |
The duration of the transition animation, measured in seconds. If you specify a negative value or |
options |
A mask of options indicating how you want to perform the animations. For a list of valid constants, see |
animations |
A block object that contains the changes you want to make to the specified view. This block takes no parameters and has no return value. This parameter must not be |
completion |
A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be |
fromView
toView:(UIView *)toView
duration:(NSTimeInterval)duration
options:(UIViewAnimationOptions)options
completion:(void (^)(BOOL finished))completion
fromView |
The starting view for the transition. By default, this view is removed from its superview as part of the transition. |
toView |
The ending view for the transition. By default, this view is added to the superview of |
duration |
The duration of the transition animation, measured in seconds. If you specify a negative value or |
options |
A mask of options indicating how you want to perform the animations. For a list of valid constants, see |
completion |
A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be |
duration
delay:(NSTimeInterval)delay
options:(UIViewKeyframeAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
uration |
The duration of the overall animation, measured in seconds. If you specify a negative value or |
delay |
Specifies the time (in seconds) to wait before starting the animation. |
options |
A mask of options indicating how you want to perform the animations. For a list of valid constants, see |
animations |
A block object containing the changes to commit to the views. Typically, you call the |
completion |
A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. You can use a |
frameStartTime
relativeDuration:(double)frameDuration
animations:(void (^)(void))animations
frameStartTime |
The time at which to start the specified animations. This value must be in the range |
frameDuration |
The length of time over which to animate to the specified value. This value must be in the range |
animations |
A block object containing the animations you want to perform. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be |
+ (void)performSystemAnimation:(UISystemAnimation)
animation
onViews:(NSArray<__kindof UIView *> *)views
options:(UIViewAnimationOptions)options
animations:(void (^)(void))parallelAnimations
completion:(void (^)(BOOL finished))completion
animation |
The system animation to perform; a constant from the |
views |
The views to perform the animations on. |
options |
A mask of options indicating how you want to perform the animations. For a list of valid constants, see |
parallelAnimations |
Additional animations you specify to run alongside the system animation, with the same timing and duration that the system animation defines or inherits. In your additional animations, do not modify properties of the view on which the system animation is being performed. |
completion |
A block object to be executed when the animation sequence ends. The single Boolean argument indicates whether or not the animations finished before the completion handler was called. If the animation duration is |
爲一個或多個視圖執行系統提供的動畫
(8)+ (void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
usingSpringWithDamping:(CGFloat)dampingRatio
initialSpringVelocity:(CGFloat)velocity
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
duration |
The total duration of the animations, measured in seconds. If you specify a negative value or |
delay |
The amount of time (measured in seconds) to wait before beginning the animations. Specify a value of |
dampingRatio |
The damping ratio for the spring animation as it approaches its quiescent state. To smoothly decelerate the animation without oscillation, use a value of |
velocity |
The initial spring velocity. For smooth start to the animation, match this value to the view’s velocity as it was prior to attachment. A value of |
options |
A mask of options indicating how you want to perform the animations. For a list of valid constants, see |
animations |
A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be |
completion |
A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be |
actionsWithoutAnimation : 視圖禁用一個動畫過渡
animationID
context:(void *)context
animationID |
An application-supplied identifier for the animations. |
context |
Custom data that you want to associate with this set of animations. information that is passed to the animation delegate messages—the selectors set using the |
startTime :爲當前的動畫設置開始的時間
enabled ; yes的時候動畫可使用,no的時候動畫不可使用
delegate ; 指定一個委託在你接受信息的時候開始或者結束動畫
selector ; 當動畫開始的時候設置消息發送給動畫委託
selector ; 當動畫結束的時候設置消息發送給動畫委託
duration:設置動畫執行的時間長度
delay ;設置多長時間後開始執行動畫
curve設置使用的曲線當動畫屬性改變的時候
repeatCount ; 設置動畫重複的時間
repeatAutoreverses ; 設置動畫是否能夠反方向重複
fromCurrentState ;設置視圖是否應該從當前的狀態開始執行動畫
transition
forView:(UIView *)view
cache:(BOOL)cache
transition |
A transition to apply to |
view |
The view to apply the transition to. |
cache |
If If |
UIView
,
effect ; 爲視圖添加一個動做功能
effect ;移除動做功能
coder ;若是你的軟件支持恢復功能,能夠爲視圖重載這個方法編碼相關狀態
coder ;從視圖解碼和保存狀態關係信息
afterUpdates ; 在基於當前內容中返回一個快照視圖
rect
afterScreenUpdates:(BOOL)afterUpdates
withCapInsets:(UIEdgeInsets)capInsets
rect |
The portion of the view that you want to capture. The rectangle must be in the bounds coordinate space of the current view. |
afterUpdates |
A Boolean value that specifies whether the snapshot should be taken after recent changes have been incorporated. Pass the value |
capInsets |
The edge insets that define the stretchable portion of the returned view’s content. You can specify |
rect
afterScreenUpdates:(BOOL)afterUpdates
rect |
A rectangle specified in the local coordinate system (bounds) of the view. |
afterUpdates |
A Boolean value that indicates whether the snapshot should be rendered after recent changes have been incorporated. Specify the value |
tag ; 返回一個特定標識的視圖
- (CGPoint)convertPoint:(CGPoint)
point
toView:(UIView *)view
point |
A point specified in the local coordinate system (bounds) of the receiver. |
view |
The view into whose coordinate system |
轉換接收者座標系統中的點到指定的視圖
(2)- (CGPoint)convertPoint:(CGPoint)point
fromView:(UIView *)view
point |
A point specified in the local coordinate system (bounds) of |
view |
The view with |
rect |
A rectangle specified in the local coordinate system (bounds) of the receiver. |
view |
The view that is the target of the conversion operation. If |
rect |
A rectangle specified in the local coordinate system (bounds) of |
view |
The view with |
point |
A point specified in the receiver’s local coordinate system (bounds). |
event |
The event that warranted a call to this method. If you are calling this method from outside your event-handling code, you may specify |
point |
A point that is in the receiver’s local coordinate system (bounds). |
event |
The event that warranted a call to this method. If you are calling this method from outside your event-handling code, you may specify |
force ,從當前視圖或者子視圖中尋找文本的響應,若是爲第一響應者就放棄這個響應,若是force爲yes那麼這個文本將會永遠不會獲得第一響應
subview ; 這個方法主要用來重載,並告訴視圖子視圖已經添加
subview ; 用來重載的時候告訴視圖子視圖已經刪除
newSuperview ; 用來重載的時候肯定將會在何時改變父視圖
newWindow ; 重載時候轉移到新的窗口
setNeedsDisplay方法能夠重畫視圖
UIViewAutoresizing的類型:
UIViewAutoresizingNone = 0, :指定視圖不調整大小
UIViewAutoresizingFlexibleLeftMargin = 1 << 0, :從左邊緣進行放大或者縮小進行調整大小
UIViewAutoresizingFlexibleWidth = 1 << 1, :經過放大或者縮小寬度來調整大小
UIViewAutoresizingFlexibleRightMargin = 1 << 2, :經過從右邊緣進行放大或者縮小來進行調整大小
UIViewAutoresizingFlexibleTopMargin = 1 << 3, :經過從上邊緣進行放大或者縮小來進行調整大小
UIViewAutoresizingFlexibleHeight = 1 << 4, :經過從高度進行放大或者縮小來調整大小
UIViewAutoresizingFlexibleBottomMargin = 1 << 5 :經過底部邊緣進行放大或者縮小來調整大小
const CGSize UILayoutFittingCompressedSize; :這個選項儘量的使用最小的尺寸
const CGSize UILayoutFittingExpandedSize; :這個選項儘量的使用最大的尺寸
10.UISemanticContentAttribute的類型:
UISemanticContentAttributeUnspecified = 0, :The view is flipped when switching between left-to-right and right-to-left layouts
UISemanticContentAttributePlayback, :A view representing the playback controls, such as Play, Rewind, or Fast Forward buttons or playhead scrubbers
UISemanticContentAttributeSpatial, :A view representing a directional control, such as a segment control for text alignment, or a D-pad control for a game.
UISemanticContentAttributeForceLeftToRight, :視圖老是從左向右佈局
UISemanticContentAttributeForceRightToLeft :視圖老是從右向左佈局