UIView之常用方法
UIView之常用方法
- 将一个视图添加为子视图,并使之在最上面显示
-(void)addSubView:(UIView *)view;
- 将指定子视图移动到顶部
-(void)bringSubViewToFront:(UIView *)view;
- 将指定之视图放到最下面
-(void)sendSubViewToBack:(UIView *)view;
- 将指定视图添加到subviews数组的index位置
-(void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
- 将指定视图添加到指定子视图下面
-(void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
- 将指定视图添加到指定子视图上面
-(void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
- 交换subviews数组中两个位置的子视图
-(void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
- 从父视图中移除
-(void)removeFromSuperview;
- 根据tag值获取对应的子孙控件
-(UIView *)viewWithTag:(NSInteger)tag;
- 将视图中点从自己的坐标系转换到指定的视图坐标系中
-(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;
- 刷新视图,调用后自动调用drawRect:(CGRect)rect
-(void)setNeedsDisplay;
- 继承自UIResponder用于响应触摸事件的方法
1.- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;2.- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;3.- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;4.- (void)touchesCancelled:(nullable NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
以上方法需要自定义view重写,若需要对触摸点到判断(使用)那么重写方法时,在方法体内首先获取触摸点:
1.UITouch *touch = [touches anyObject];2.CGPoint point = [touch locationInView:self];
- 动画
1.// 首先需要设置动画头,告诉编译器下面是动画2.[UIView beginAnimations:nil context:nil];3.// 再设置动画执行的配置、动画4.[UIView setAnimationDuration:0.5];5.[UIView setAnimationRepeatCount:2];6.[UIView setAnimationDelay:3.0];7.// balabala需要执行的动画8. ................9.// 最后提交动画10.[UIView commitAnimations];
- 使用block设置动画
- 方法一
+(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;
- 方法二
+(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion
- 方法三
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion
- 方法一
转载于:https://www.cnblogs.com/buakaw/p/5069287.html
UIView之常用方法相关推荐
- iOS 初学者功能代码大集合,个人笔记
UitableView cell 高度自适应 Masonry UILabel iOS UI控件 1.UIButton按钮 2.UILabel文本标签 3.UITextField文本输入框 4.UII ...
- iOS开发中那些容易被我们忽略的代码,常用代码集合
退回输入键盘 - (BOOL) textFieldShouldReturn:(id)textField{ [textField resignFirstResponder]; } CGRect CGRe ...
- 【 iOS 应用开发 】 UIKit 控件 ( 代码生成控件 | UIView 属性方法 | Storyboard | Bundle | Property List | 动画 | 图片内存优化 )
文章目录 一. 代码生成控件 1. 创建设置项目 ( 1 ) 创建项目 ( ① 选择 Create a new Xcode project | ② 创建 Single View Application ...
- UIApplication,UIWindow,UIViewController,UIView(layer)
转载自:http://www.cnblogs.com/iCocos/p/4684749.html UIApplication,UIWindow,UIViewController,UIView(laye ...
- 学习IOS开发UI篇--UIView\UIButton\UILabel\UIImageView\UITextField
UIView\UIButton\UILabel\UIImageView\UITextField,这些都是UI中常用的比较简单地类. 所有的UI类都继承自UIView,所以都有共同的属性,frame,b ...
- UITextField leftView 光标的边距 监听return键 字符长度的限制 以及其他的常用方法
1.UITextField的光标太靠近边框 设置leftView 使光标和左侧边框的距离变大 UITextField *textField = [[UITextField alloc]initWith ...
- iPone应用开发 UIView 常用属性和方法
程序开发-uiview常用属性和方法">iPone应用程序开发 UIView常用属性和方法 常用属性 alpha 视图的透明度0.0f - 1.0f backgroundColor 视 ...
- 30 个 php 操作 redis 常用方法代码例子
这篇文章主要介绍了 30 个 php 操作 redis 常用方法代码例子 , 本文其实不止 30 个方法 , 可以操作 string 类 型. list 类型和 set 类型的数据 , 需要的朋友可以 ...
- SearchRequestBuilder常用方法说明
SearchRequestBuilder常用方法说明 (1) setIndices(String... indices):上文中描述过,参数可为一个或多个字符串,表示要进行检索的index:(2) s ...
最新文章
- 【组队学习】【29期】7. 集成学习(上)
- python3中的单例模式Singleton
- PC软件开发技术之二:用C#开发基于自动化接口的OPC客户端
- WiMAX版图不止3G
- 深入学习软件测试:混合正交表工具
- matlab johnson变换,johnson算法是什么?
- 机器学习实战应用案例100篇(十二)-樽海鞘算法从原理到实战应用案例
- php 翻转180度,如何翻转视频—将视频翻转90或180度
- 解决Centos7网络连接的问题
- 《星际穿越》科学解析
- 投票动态代理proxy案例(java)
- 图像修复神器!带上口罩都能还原!DDPM:用去噪扩散概率模型极限修复图像,效果太牛了!...
- 计算机网络管理工作记录,网络管理如何查看电脑开机、关机记录
- c语言程序设计1253,1253c语言程序设计a(2010年1月)
- 跨层中介作用模型2-1-1的Mplus语法
- 烤仔建工 | Wearable Dao时装秀倒计时!在元宇宙里穿上“中国红”!
- 拨乱反正:“通过RAMDirectory缓写提高性能”是错误的!
- 8.关于删除操作中axis=0和axis=1的理解(Python版)
- 数据库原理课程设计 — 学业课程预警系统
- 机器人基础原理1_1——机器人概念及发展历程
热门文章
- cin、cin.get()、cin.getline()、getline()、gets()等函数的用法(转)
- 一个产品留言统计查寻的分析比较
- DOM-2 document对象、获取元素、节点、遍历树
- 前端安全之token
- Python黑科技:在家远程遥控公司电脑,python+微信一键连接!
- 老男孩linux运维50期
- 绝非玩笑!人工智能或开创黑客新时代
- “高考”机器人横空出世 2017年居然要考“大学”
- 看看你的网站有几个这样的链接?
- 快速查询DB Lock的方法