iOS-UIView官方API列举

一 概念

UIView类定义了一块矩形区域,其具有三大功能:

  • 画图和动画
  • 布局和管理子视图
  • 事件处理

二 初始化,及其相关属性

2.1 初始化

1
2
initWithFrame:
initWithCoder://这个方法基本不会用到,除非你是使用IB来生成的视图,博主还未考证

2.2 配置有关外观的属性

1
2
3
4
5
6
7
8
9
10
11
backgroundColor
hidden
alpha
opaque
tintColor
tintAdjustmentMode
clipsToBounds
clearsContextBeforeDrawing
maskView
layerClass
layer

2.3 配置事件相关的属性

1
2
3
userInteractionEnabled
multipleTouchEnabled
exclusiveTouch //只响应触摸事件

2.4 配置bounds和frame相关的属性

1
2
3
4
5
6
7
frame
bounds
上述两者的区别是:前者是以其superView为参考坐标,来描述其本身的位置和size,后者是以自己本身为参考坐标,来描述其本身的位置和size.
center
transform :旋转相关的属性

三 管理视图的视图层级

1
2
3
4
5
6
7
8
9
10
11
12
13
superview
subviews
window
*********************华丽的分割线********************
- addSubview:
- bringSubviewToFront:
- sendSubviewToBack:
- removeFromSuperview
- insertSubview:atIndex:
- insertSubview:aboveSubview:
- insertSubview:belowSubview:
- exchangeSubviewAtIndex:withSubviewAtIndex:
- isDescendantOfView: //Returns a Boolean value indicating whether the receiver is a subview of a given view or identical to that view.

四 管理手势

1
2
3
4
- addGestureRecognizer:
- removeGestureRecognizer:
gestureRecognizers
- gestureRecognizerShouldBegin:

五 动画相关

1
2
3
4
5
6
7
8
9
10
+ animateWithDuration:delay:options:animations:completion:
+ animateWithDuration:animations:completion:
+ animateWithDuration:animations:
+ transitionWithView:duration:options:animations:completion:
+ transitionFromView:toView:duration:options:completion:
+ animateKeyframesWithDuration:delay:options:animations:completion:
+ addKeyframeWithRelativeStartTime:relativeDuration:animations:
+ performSystemAnimation:onViews:options:animations:completion:
+ animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:
+ performWithoutAnimation:

六 截图相关的办法(7.0)

1
2
3
4
- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates NS_AVAILABLE_IOS(7_0);
- (UIView *)resizableSnapshotViewFromRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates withCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(7_0); // Resizable snapshots will default to stretching the center
// Use this method to render a snapshot of the view hierarchy into the current context. Returns NO if the snapshot is missing image data, YES if the snapshot is complete. Calling this method from layoutSubviews while the current transaction is committing will capture what is currently displayed regardless if afterUpdates is YES.
- (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates NS_AVAILABLE_IOS(7_0);

七 确认View在运行时

1
2
tag
-(UIView *)viewWithTag:

八 hit Testing in a View

1
2
- hitTest: withEvent:
- pointInside: withEevent:

九 放弃第一响应者

1
- endEditing

十 获得视图相关的变化

1
2
3
4
5
6
- didAddSubview:
- willRemoveSubview:
- willMoveToSuperview:
- didMoveToSuperview
- willMoveToWindow:
- didMoveToWindow

十一 观察焦点

1
2
3
canBecomeFocused
inheritedAnimationDuration
focused

#十二 跟约束相关的方法和属性
由于这个基本用不到 所以不做解释了

坚持原创技术分享,您的支持将鼓励我继续创作!