好了,我接着上篇,开始我们的对UIView 实例方法的探索
UIView 实例方法 Instance Methods

初始化一个视图
- (id)initWithFrame:(CGRect)aRect //用指定的frame 初始化一个视图对象

结束视图中的编辑状态
- (BOOL)endEditing:(BOOL)force
//这个在弹回键盘时特别有用

关于响应
- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
//为视图添加一个手势识别器
- (void)removeGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
//移除一个手势识别器
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
//开始一个手势识别器
- (void)addMotionEffect:(UIMotionEffect *)effect
//开始向视图中添加运动效果,这么说其实比较模糊,比如说警告框会随着手机的倾斜而倾斜,
当然这需要代码实现,只是我们现在可以检测手机的运动事件来做出相应的响应
//从IOS7开始使用

管理视图层次 Managing the View Hierarchy

- (void)addSubview:(UIView *)view //添加子视图
- (void)removeFromSuperview //从父视图中移除

- (void)bringSubviewToFront:(UIView *)view
//移动指定的子视图到最顶层
- (void)sendSubviewToBack:(UIView *)view
//移动制定的子视图到后方,所有子视图的下面

- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index
//在指定的位置插入子视图,视图的所有视图其实组成了一个数组
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview
//将指定的子视图移动到指定siblingSubview子视图的前面
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview
//将指定的子视图移动到指定siblingSubview子视图的后面
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2
//交换两子视图的位置

- (BOOL)isDescendantOfView:(UIView *)view
//判断接收对象是否是指定视图的子视图,或与指定视图是同一视图

配置自动调整大小状态 Configuring the Resizing Behavior
- (void)sizeToFit //根据子视图的大小位置,调整视图,使其恰好围绕子视图,
也就是说自动适应子视图的大小,只显示子视图
- (CGSize)sizeThatFits:(CGSize)size
//让视图计算最适合子视图的大小,即能把全部子视图显示出来所需要的最小的size

铺设子视图 Laying out Subviews

- (void)layoutSubviews //勾画子视图
- (void)layoutIfNeeded //立即勾画子视图
- (void)setNeedsLayout
//使当前接收对象的布局作废,并在下一更新周期触发一个新的布局

选择加入基于约束的布局 Opting in to Constraint-Based Layout

- (void)setTranslatesAutoresizingMaskIntoConstraints:(BOOL)flag
//设置视图自动调整尺寸的掩码是否转化为基于约束布局的约束
- (BOOL)translatesAutoresizingMaskIntoConstraints
//判断视图是否将自动调整尺寸的掩码是否转化为基于约束布局的约束

管理约束 Managing Constraints

- (NSArray *)constraints //返回由视图创建的约束

- (void)addConstraint:(NSLayoutConstraint *)constraint
//为视图布局或者子视图添加一个约束,constraint约束只能在当前视图范围内,包括子视图
- (void)addConstraints:(NSArray *)constraints
//添加一组约束

- (void)removeConstraint:(NSLayoutConstraint *)constraint
//移除视图上指定的约束
- (void)removeConstraints:(NSArray *)constraints
//移除指定的一组约束

在基于约束布局的测量 Measuring in Constraint-Based Layout

- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize
//返回满足持有约束的视图的size

- (CGSize)intrinsicContentSize
//返回接收对象的原本大小

- (void)invalidateIntrinsicContentSize
//废除视图原本内容的size

- (UILayoutPriority)contentCompressionResistancePriorityForAxis:(UILayoutConstraintAxis)axis
//设置当视图要变小时,视图的压缩改变方式,是水平缩小还是垂直缩小,并返回一个优先权
- (void)setContentCompressionResistancePriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis
//设置优先权

- (UILayoutPriority)contentHuggingPriorityForAxis:(UILayoutConstraintAxis)axis
//与上边相反是视图的放大改变方式
- (void)setContentHuggingPriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis
//参照上面的方法

校准视图 Aligning Views with Constraint-Based Layout

- (CGRect)alignmentRectForFrame:(CGRect)frame
//返回给定框架的视图的对齐矩阵
- (CGRect)frameForAlignmentRect:(CGRect)alignmentRect
//返回给定对齐矩形的视图的frame
- (UIEdgeInsets)alignmentRectInsets
//返回从视图的frame上定义的对齐矩阵的边框
- (UIView *)viewForBaselineLayout
//返回满足基线约束条件的视图

触发基于约束的布局 Triggering Constraint-Based Layout

- (BOOL)needsUpdateConstraints //视图的约束是否需要更新
- (void)setNeedsUpdateConstraints //设置视图的约束需要更新

- (void)updateConstraints //为视图更新约束
- (void)updateConstraintsIfNeeded //更新视图和其子视图的约束

调试基于约束的布局 Debugging Constraint-Based Layout

- (NSArray *)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis
//返回影响一个给定轴视图布局的约束

- (BOOL)hasAmbiguousLayout //视图的位置是否不完全指定

- (void)exerciseAmbiguityInLayout
//在不同的有效值之间用一个模糊的布局随机改变视图的frame

绘画和更新视图 Drawing and Updating the View

- (void)drawRect:(CGRect)rect //在指定的区域绘画视图

- (void)setNeedsDisplay //标记整个视图的边界矩形需要重绘
- (void)setNeedsDisplayInRect:(CGRect)invalidRect
//标记在指定区域内的视图的边界需要重绘

格式化打印视图内容

- (UIViewPrintFormatter *)viewPrintFormatter //返回视图的打印格式化

- (void)drawRect:(CGRect)area forViewPrintFormatter:(UIViewPrintFormatter *)formatter
//指定区域和打印格式绘画视图内容

保存和恢复状态 Preserving and Restoring State

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
//编码视图的状态信息
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder
//解码一个视图状态信息

标记视图
- (UIView *)viewWithTag:(NSInteger)tag

转换视图间坐标 Converting Between View Coordinate Systems

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view
//转换一个点从接受对象的坐标系到指定视图
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view
//与上面相反,指定视图坐标中的一个点转换为接收对象

- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view
//参照上面两个方法

视图中的点击测试

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
//在指定点上点击测试指定事件
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
//测试指定的点是否包含在接收对象中

注意与视图相关联的改变 Observing View-Related Changes

- (void)didAddSubview:(UIView *)subview
//通知视图指定子视图已经添加
- (void)willRemoveSubview:(UIView *)subview
//通知视图将要移除指定的子视图

- (void)willMoveToSuperview:(UIView *)newSuperview
//通知视图将要移动到一个新的父视图中
- (void)didMoveToSuperview
//通知视图已经移动到一个新的父视图中

- (void)willMoveToWindow:(UIWindow *)newWindow
//通知视图将要移动到一个新的window中
- (void)didMoveToWindow
//通知视图已经移动到一个新的window中

以上即是UIView 类的实例方法,比较多,我按照文档把它分为了几类。

到此为止这个类差不多已经了解了大概,正如我所期望的那样,要知道
这个类中都有什么东西,以后不至于走很多弯路。

 

UIView 实例方法 Instance Methods(转)的更多相关文章

  1. Swift编程语言学习12 ——实例方法(Instance Methods)和类型方法(Type Methods)

    方法是与某些特定类型相关联的函数.类.结构体.枚举都能够定义实例方法:实例方法为给定类型的实例封装了详细的任务与功能.类.结构体.枚举也能够定义类型方法:类型方法与类型本身相关联.类型方法与 Obje ...

  2. Java SE 8 docs——Static Methods、Instance Methods、Abstract Methods、Concrete Methods和field

    一.Static Methods.Instance Methods.Abstract Methods.Concrete Methods ——Static Methods:静态方法 ——Instance ...

  3. Mongoose 'static' methods vs. 'instance' methods

    statics are the methods defined on the Model. methods are defined on the document (instance). We may ...

  4. Instance Methods are Curried Functions in Swift

    An instance method in Swift is just a type method that takes the instance as an argument and returns ...

  5. Static and Instance Methods in JavaScript

    class.method/instance method https://abdulapopoola.com/2013/03/30/static-and-instance-methods-in-jav ...

  6. Android JNI 学习(八):Calling Instance Methods Api

    一.GetMethodID jmethodIDGetMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig); 返回 ...

  7. Objective-C 入门(给新人的)

    http://www.hengxinsoft.com/2010/12/objective-c-%E5%85%A5%E9%97%A8%EF%BC%88%E7%BB%99%E6%96%B0%E4%BA%B ...

  8. Swift3.0P1 语法指南——方法

    原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...

  9. swift学习笔记之-方法部分

    //方法部分 import UIKit //方法(Methods) /*方法是与某些特定类型相关联的函数,类.结构体.枚举都可以定义实例方法 实例方法(Instance Methods): 1.属于某 ...

随机推荐

  1. 5.6(java学习笔记) queue

    一.queue接口 queue的中文意思是队列,是一种以先进先出方式处理数据的集合. 队列还提供额外的插入.提取和检查操作.这些方法都以两种形式存在:一种在操作失败时抛出异常,另一种返回特殊值(根据操 ...

  2. redis踩坑记

    本来打算给一批主库做从库,用来读取数据,还不想碰主库数据. 主库redis2.8.12,从库一开始没注意,docker了一个3.1的,结果slaveof之后命令不兼容,下了一个2.8的(2.8.23好 ...

  3. cojs.tk(所有题目来源) 树状数组专练

    1.求和问题 ★   输入文件:sum.in   输出文件:sum.out   简单对比时间限制:1.2 s   内存限制:128 MB [问题描述]     在一个长度为n的整数数列中取出连续的若干 ...

  4. Scala实战高手****第8课:零基础实战Scala最常用数据结构Map和Tuple及Spark源码鉴赏

    本课内容1.Map和Tuple在Spark源码中的鉴赏2.Map和Tuple代码操作实战 ------------------------------------------------------- ...

  5. IntelliJ 常用设置

    一.智能代码提示忽略大小写 打开设置(CTRL+ALT+S)搜索editor,找到“Code Completion”->点击Case sensitive completion后面的选择框,选中N ...

  6. 基于jquery类库的绘制二维码的插件jquery.qrcode.js

     jquery.qrcode.min.js 如下 (function(r){r.fn.qrcode=function(h){var s;function u(a){this.mode=s;this.d ...

  7. Python扫描指定文件夹下(包含子文件夹)的文件

    扫描指定文件夹下的文件.或者匹配指定后缀和前缀的函数. 假设要扫描指定文件夹下的文件,包含子文件夹,调用scan_files("/export/home/test/") 假设要扫描 ...

  8. 利用“进程注入”实现无文件复活 WebShell

    引子 上周末,一个好兄弟找我说一个很重要的目标shell丢了,这个shell之前是通过一个S2代码执行的漏洞拿到的,现在漏洞还在,不过web目录全部不可写,问我有没有办法搞个webshell继续做内网 ...

  9. oracle 10g函数大全--转换函数

    chartorowid(c1) [功能]转换varchar2类型为rowid值 [参数]c1,字符串,长度为18的字符串,字符串必须符合rowid格式 [返回]返回rowid值 [示例] SELECT ...

  10. 依据出生日期Date 计算年龄

    依据出生日期计算年龄 public class DateGetAge { public static int getAge(Date birthDay) throws Exception { Cale ...