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 ...
随机推荐
- KV总结
今天没事又重新写了一遍.很多注释是自己犯糊涂后来又终于跨过去的备忘. // ImgEff.js function ImgEff(div,time){ //构造函数,需要传入参数div的id和时间 // ...
- Eclipse maven git
http://www.blogjava.net/youxia/archive/2013/12/29/408182.html
- 字符串(后缀自动机):NOI 2016 优秀的拆分
[问题描述] 如果一个字符串可以被拆分为 AABB 的形式,其中 A 和 B 是任意非空字符串, 则我们称该字符串的这种拆分是优秀的. 例如,对于字符串 aabaabaa,如果令 A = aab, B ...
- 杂题 SPOJ MOBILE2 - Mobiles
MOBILE2 - Mobiles no tags You have been asked to buy a gift for your baby brother, Ike. However, yo ...
- 网络流(最小费用最大流):POJ 2135 Farm Tour
Farm Tour Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: ...
- 【单调队列】Vijos P1771 瑞士轮 (NOIP2011普及组第三题)
题目链接: https://vijos.org/p/1771 题目大意: 给定2N个人(N<=100 000)和其初始分数.能力值(能力两两不同),比赛M次(M<=50),每次PK都是按分 ...
- Mac下Shell快捷键
ctrl+a //移到行首 ctrl+e //移到行尾 ctrl+y // 插入最近删除的单词或语句 ctrl+k //删除光标处到行尾部分 ctrl+u //删除光标处到行首部分 ctrl+w // ...
- HDOJ(HDU) 2212 DFS(阶乘相关、)
Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every d ...
- cf703A Mishka and Game
A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Jenkins 四: 启动关闭以及重启jenkins
启动 1. 在桌面新建一个jenkins.bat文件.内容如下: cd /d %JENKINS_HOME% java -jar %JENKINS_HOME%\jenkins.war --httpPor ...