UIKit之UIView

来源:互联网 发布:转发长视频软件 编辑:程序博客网 时间:2024/06/18 18:22

UIView(UIViewGeometry)

@property(nonatomic) CGRect            frame;

设置和获取视图的边框大小

@property(nonatomic) CGRect            bounds;

设置和获取视图的边界大小

@property(nonatomic) CGPoint           center;

返回中心点坐标

@property(nonatomic) CGAffineTransform transform;

用于在二维空间做旋转,缩放和平移。

@property(nonatomic) CGFloat           contentScaleFactor

应用到当前视图的比例Scale

@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled

是否支持多点触控

@property(nonatomic,getter=isExclusiveTouch) BOOL       exclusiveTouch

exclusiveTouch的意思是UIView会独占整个Touch事件,具体的来说,就是当设置了exclusiveTouch的 UIView是事件的第一响应者,那么到你的所有手指离开前,其他的视图UIview是不会响应任何触摸事件的,对于多点触摸事件,这个属性就非常重要,值得注意的是:手势识别(GestureRecognizers)会忽略此属性。

- (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event;
- (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event;
- (CGPoint)convertPoint:(CGPoint)point toView:(nullable UIView *)view;

将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值

- (CGPoint)convertPoint:(CGPoint)point fromView:(nullable UIView *)view;

将像素point从view中转换到当前视图中,返回在当前视图中的像素值

- (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;

将rect由rect所在视图转换到目标视图view中,返回在目标视图view中的rect

- (CGRect)convertRect:(CGRect)rect fromView:(nullable UIView *)view;

将rect从view中转换到当前视图中,返回在当前视图中的rect

@property(nonatomic) BOOL               autoresizesSubviews;

在设置边框大小时,是否自动调整子视图的大小

@property(nonatomic) UIViewAutoresizing autoresizingMask;

子视图自动调整的掩码,怎么自动调整子视图。用于子视图。

typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {    UIViewAutoresizingNone                 = 0,//不做调整    UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,//调整左边距    UIViewAutoresizingFlexibleWidth        = 1 << 1,//调整宽度    UIViewAutoresizingFlexibleRightMargin  = 1 << 2,//调整右边距    UIViewAutoresizingFlexibleTopMargin    = 1 << 3,//调整上边距    UIViewAutoresizingFlexibleHeight       = 1 << 4,//调整高度    UIViewAutoresizingFlexibleBottomMargin = 1 << 5 //调整下边距};

UIView(UIViewHierarchy)

视图的子视图之间存在层次的关系。层次越高的视图,越显示在前面,越不容易被挡住。层次的高低是按照加入的顺序排的。加入的越晚,层次越高。

@property(nullable, nonatomic,readonly) UIView       *superview;

视图的父视图

@property(nonatomic,readonly,copy) NSArray<__kindof UIView *> *subviews;

视图的所有子视图

@property(nullable, nonatomic,readonly) UIWindow     *window;

视图的窗口

- (void)removeFromSuperview;

从父视图中删除视图

- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;

将视图插入到index下标处

- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;

交换两个视图的位置

- (void)addSubview:(UIView *)view;

添加视图

- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;

在siblingSubview下面添加视图

- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;

在siblingSubview上面添加视图

- (void)bringSubviewToFront:(UIView *)view;

将视图view放置在视图的最前面

- (void)sendSubviewToBack:(UIView *)view;

将视图view放置在视图的最后面

- (void)didAddSubview:(UIView *)subview;

已经添加视图时调用(可重写此方法完成需要功能)

- (void)willRemoveSubview:(UIView *)subview;

将要删除视图时调用(可重写此方法完成需要功能)

- (void)willMoveToSuperview:(nullable UIView *)newSuperview;

将要移动到父视图时调用(可重写此方法完成需要功能)

- (void)didMoveToSuperview;

移动到父视图时调用(可重写此方法完成需要功能)

- (void)willMoveToWindow:(nullable UIWindow *)newWindow;

将要移动到窗口时调用(可重写此方法完成需要功能)

- (void)didMoveToWindow;

移动到窗口时调用(可重写此方法完成需要功能)

- (BOOL)isDescendantOfView:(UIView *)view;

视图view是否是视图的祖先

- (nullable __kindof UIView *)viewWithTag:(NSInteger)tag;

根据tag标签的值获取对应的视图(视图可以设置tag标签值,一般从100开始)