UIkit框架之Uivew
1.继承链:UIresponder:NSObject
2.通过使用 addGestureRecognizer:方法可以为视图添加手势
3.下面的属性都可以用来用于动画
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 :视图总是从右向左布局