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
- 方法一
UIView之常用方法的更多相关文章
- UIView的常用方法
bringSubviewToFront: 把指定的子视图移动到顶层 - (void)bringSubviewToFront:(UIView *)view 参数 view 需要移到顶层的视图 conve ...
- iOS UIView非常用方法及属性详解
在调用视图的 Quartz 调用都可以正确地在视图中描画. 视图对象通过 bounds .和 center 属 性声明来跟踪自己的大小和位置.frame 属性包含一个矩形,即边框矩形,用于指定 ...
- Swift - UIView的常用属性和常用方法总结
1,UIView常用的一些属性如下: frame:相对父视图的坐标和大小(x,y,w,h) bounds:相对自身的坐标和大小,所以bounds的x和y永远为0(0,0,w,h) center:相对父 ...
- 轻量级应用开发之(02)UIView
一 控件 1.屏幕上的所有UI元素都叫做控件(也有叫做视图.组件)比如按钮(UIButton).文本(UILabel)都是控件. 2.控件的共同属性有哪些? 尺寸,位置,背景色 3. 苹果将控件的共同 ...
- [转] 关于UIView
[转载] 原文地址 :http://blog.csdn.net/itianyi/article/details/8982518 UIView是开发中使用得最多的控件了,深入的理解很有必要. UIVie ...
- iOS用心学 UI基础之UIView
一.引入UI 在实际开发中,基本的流程大致如下图所示: UI(User Interface)作为最基本的要点,也是非常重要的一部分,UI界面的美观直接决定着着用户的体验,苹果官方给开发中提供了非常强大 ...
- UIView的作用
UIView [UIView的作用] 主要用来显示应用程序的内容,可以作为label.button等控件的容器.表示屏幕上的一块矩形区域,同时可以处理该区域的绘制和触屏事件. MVC,MVVM等设计架 ...
- UIWindow与UIView
UIView与UIWindow * 一般应用程序只有一个UIWindow对象.所有的控件都是在UIWindow上展现的.每个UIView对象都有一个window属性,表示当前view显示在哪个窗体上. ...
- UI--普通控件总结1--控件使用
本文目录 0.UIView常用的属性和操作 0_1.UIView常见的属性 0_2.UIView状态 0_3.UIView常用的方法 1.文本框UITextField和文本视图UITextView 1 ...
随机推荐
- jQuery Asynchronous
http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html http:// ...
- Unity3d 基础知识学习 工具篇
Unity3d 层(layer)的学习 @广州小龙 unity中的层是个很有用的东西, 点击层的下拉框,点击Add Layer,可以打开层管理器,我新建了一个层为test 他的id值是8,这个后面会 ...
- 利用over开窗函数取第一条记录
SQL> set linesize 200 SQL> select * from (select a.* ,row_number() over( order by empno) rn f ...
- For循环练习之99乘法表和转义字符
之前说了for循环的概念以及常用到的操作,那么我们接下来做几个巩固练习: 1.打印99乘法表: 99乘法表的形式: 1*1 = 1 1*2 = 2 2*2 = 4 1*3 = 3 2*3 = 6 3* ...
- VS2010中fatal error LNK1123错误的解决方案
问题描述: 在VS2010项目编译时会出现如下错误:LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 解决方案: 查找是否有两个cvtres.exe ...
- The Same Game(模拟)
http://poj.org/problem?id=1027 题意:给一个10*15的地图,里面填充R,G,B三种颜色,每次找到当前地图的同色最大区域M,并将其删除,删除M后,上面的小球自然下落,当有 ...
- Linux kernel ‘net/key/af_key.c’信息泄露漏洞
漏洞名称: Linux kernel ‘net/key/af_key.c’信息泄露漏洞 CNNVD编号: CNNVD-201307-071 发布时间: 2013-07-05 更新时间: 2013-07 ...
- Delphi TdxComponentPrinter页头页脚的设定
TdxComponentPrinter页头页脚的设定 抄一段备忘.用程序控制也一样.如果是这样,那么 双击TdxComponentPrinter控件,在出现的窗口中,点击ADD,建立一个与TcxGri ...
- HDOJ 2056 Rectangles
Problem Description Given two rectangles and the coordinates of two points on the diagonals of each ...
- poj3294 Life Forms(后缀数组)
[题目链接] http://poj.org/problem?id=3294 [题意] 多个字符串求出现超过R次的最长公共子串. [思路] 二分+划分height,判定一个组中是否包含不小于R个不同字符 ...