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
时间: 2024-07-28 19:57:26

UIView之常用方法的相关文章

iOS UIView非常用方法及属性详解

在调用视图的 Quartz  调用都可以正确地在视图中描画. 视图对象通过 bounds .和 center  属 性声明来跟踪自己的大小和位置.frame 属性包含一个矩形,即边框矩形,用于指定视图相对于其父视图坐标系统的位置和大小.bounds 属性也包含一个矩形,即边界矩形,负责定义视图相对于本地坐标系统的位置和大小.虽然边界矩形的原点通常被设置为(0, 0),但这并不是必须的.center 属性包含边框矩形的中心点. 当您在代码中通过 initWithFrame :方法创建一个视图对象时

UIView的常用方法

bringSubviewToFront: 把指定的子视图移动到顶层 - (void)bringSubviewToFront:(UIView *)view 参数 view 需要移到顶层的视图 convertPoint:fromView: 把一个点从一个坐标系转换到接收者的坐标系 - (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view 参数 point 一个视图中坐标系上的点 view 一个视图包含了点和他自身坐标系.如果是图是n

Swift - UIView的常用属性和常用方法总结

1,UIView常用的一些属性如下: frame:相对父视图的坐标和大小(x,y,w,h) bounds:相对自身的坐标和大小,所以bounds的x和y永远为0(0,0,w,h) center:相对父视图的中点坐标 transform:控制视图的放大缩小和旋转 superview:获取父视图 subviews:获取所有子视图 alpha:视图的透明度(0.0-1.0) tag:视图的标志(Int类型,默认等于0),设置后,可以通过viewWithTag方法拿到这个视图 2,UIView的常用方法

UIView的理解 [转]

[转载] 原文地址 :http://blog.csdn.net/itianyi/article/details/8982518 UIView是开发中使用得最多的控件了,深入的理解很有必要. UIView是组成画面的基本元素, NS_CLASS_AVAILABLE_IOS(2_0)@interface UIView :UIResponder<NSCoding,UIAppearance, UIAppearanceContainer> { @package CALayer        *_laye

【iOS开发】关于UIView总结与UIButton使用

一个UIVew中有好多button,怎么区分他们呢?原来每个控件都有一个tag属性 UIButton也有一个tag属性,只要设置每个button为不同的属性就可以区分他们. <span style="color:#cc33cc;">NSInteger tag = button.tag;</span> 获取button的tag值. -------------------------------------------------------------------

UI控件

在iOSAPP中,能在屏幕上显示的按钮.文本标签.文字输入框等等,都是UI控件. UIview: 苹果把所有UI控件的共同属性抽出来放在UIView中,即所有UI控件都是UIView的子类(不一定是直接子类). 注意:UIView继承自UIresponder,可以响应用户的操作. UIView的重要属性 frame:View的位置和宽高 bounce:相对于自己的左上角的位置和宽高 center:中心点的坐标 backgroundcolor:背景颜色 UIView的常用方法:UIView既可以显

iOS开发——动画OC篇&amp;所有常用动画总结

所有常用动画总结 先来装下B,看不懂没关系,其实我也看不懂-?? iOS provides several different frameworks for adding graphics and animations to your apps. UIKit is an Objective-C API that provides basic 2D drawing, image handling, and ways to animate user interface objects. Core G

UIViewController的基本概念与生命周期

UIViewController是iOS顶层视图的载体及控制器,用户与程序界面的交互都是由UIViewController来控制的,UIViewController管理UIView的生命周期及资源的加载与释放. UIView与UIWindow共同展示了应用程序的用户界面.可以将UIView理解成画布,UIWindow理解成画框.这两个类的继承关系是这样的: NSObject — UIResponder — UIView — UIWindow iOS中,所有显示在界面上的对象都是从UIRespon

iOS UIKit:view

1.View架构 1.1 简介 UIView表示屏幕上的一块矩形区域,它在App中占有绝对重要的地位,因为IOS中几乎所有可视化控件都是UIView的子类.UIView的功能 :         1) 管理矩形区域里的内容:         2) 处理矩形区域中的事件:         3) 子视图的管理:         4) 实现动画. 图 11 UIView及子类继承关系 1.2 基本结构体         1) CGPoint        该结构表示在二维坐标系中的坐标点. struc