【UIKit-124-2】#import <UIKit/UIView.h>
来源:互联网 发布:驾驶远程教育计时软件 编辑:程序博客网 时间:2024/05/21 07:09
【层级关系】
@interface UIView(UIViewHierarchy)
@property(nonatomic,readonly) UIView *superview;
@property(nonatomic,readonly,copy) NSArray *subviews;//遍历控件用
@property(nonatomic,readonly) UIWindow *window;
NSArray *views = self.view.subviews; for (NSInteger ii = 0; ii < views.count; ii++) { if ([[views objectAtIndex:ii] isKindOfClass:[UIButton class]]) { UIButton *btn = (UIButton *)[views objectAtIndex:ii]; [btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside]; } }
【添加,移除,交换层级】
- (void)removeFromSuperview;//移除
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;//在。。位置插入
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;//交换
- (void)addSubview:(UIView *)view;//添加
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;//在。。下面插入
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;//在。。上面插入
- (void)bringSubviewToFront:(UIView *)view;//移到最顶层
- (void)sendSubviewToBack:(UIView *)view;//置于最底层
-(void)soeasy{<span style="white-space:pre"></span>NSLog("不写了");}
【重写已经,将要】
- (void)didAddSubview:(UIView *)subview;//已经添加子视图
- (void)willRemoveSubview:(UIView *)subview;//将要移除子视图
- (void)willMoveToSuperview:(UIView *)newSuperview;//将要添加到父视图
- (void)didMoveToSuperview;//已经添加到父视图
- (void)willMoveToWindow:(UIWindow *)newWindow;//将要展示到屏幕
- (void)didMoveToWindow;//已经展示到屏幕
-(void)didAddSubview:(UIView *)subview{ NSLog(@"3didAddSubview"); }-(void)willRemoveSubview:(UIView *)subview{ NSLog(@"willRemoveSubview"); }- (void)willMoveToSuperview:(UIView *)newSuperview{ NSLog(@"1willMoveToSuperview");}- (void)didMoveToSuperview{ NSLog(@"2didMoveToSuperview");}- (void)willMoveToWindow:(UIWindow *)newWindow{ NSLog(@"4willMoveToWindow");}- (void)didMoveToWindow{ NSLog(@"5didMoveToWindow");}
【判断是否是子视图,tag后去视图】
- (BOOL)isDescendantOfView:(UIView *)view; //判断view是否是自己否控件
greenView = [[UIView alloc]initWithFrame:CGRectMake(100, 200, 100, 100)]; greenView.backgroundColor = [UIColor greenColor]; [self.view addSubview:greenView]; if ([greenView isDescendantOfView:self.view]) { NSLog(@"yes"); }
- (UIView *)viewWithTag:(NSInteger)tag; //通过tag,获取控件
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setFrame:CGRectMake(111, 111, 111, 111)]; button.backgroundColor = [UIColor purpleColor]; button.tag = 1000; [self.view addSubview:button]; //通过tag 获取UIView,转换成UIButton, UIButton *btn = (UIButton *)[self.view viewWithTag:1000]; [btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
【自动布局,重新布局】
- (void)setNeedsLayout;//标记需要重新布局
- (void)layoutIfNeeded;//重新布局
- (void)layoutSubviews;// 重新布局
//假设blueView 是通过自动布局,先标记,在布局。 [blueView setNeedsLayout]; [blueView layoutIfNeeded];
@end
- 【UIKit-124-2】#import <UIKit/UIView.h>
- 【UIKit-124-1】#import <UIKit/UIView.h>
- 【UIKit-124-3】#import <UIKit/UIView.h>
- 【UIKit-124-4】#import <UIKit/UIView.h>
- 【UIKit-124-5】#import <UIKit/UIView.h>
- 【UIKit-124-6】#import <UIKit/UIView.h>
- 【UIKit-124-7】#import <UIKit/UIView.h>
- 【UIKit-124-8】#import <UIKit/UIView.h>
- 【UIKit-124-9】#import <UIKit/UIView.h>
- 【UIKit-124-10】#import <UIKit/UIView.h>
- 【UIKit-124-11】#import <UIKit/UIView.h>
- 【UIKit-125-2】#import <UIKit/UIViewController.h>
- 【UIKit-93-2】#import <UIKit/UIScrollView.h>
- 【UIKit-125-1】#import <UIKit/UIViewController.h>
- 【UIKit-125-3】#import <UIKit/UIViewController.h>
- 【UIKit-125-4】#import <UIKit/UIViewController.h>
- 【UIKit-125-6】#import <UIKit/UIViewController.h>
- 【UIKit-125-7】#import <UIKit/UIViewController.h>
- 过了两周的大二
- hadoop/Spark Locality
- 怎么获得属性表的field
- Servlet与JSP的区别
- Unix File diff 命令的python 简单实现
- 【UIKit-124-2】#import <UIKit/UIView.h>
- Volley源码简读
- 线段树 模板
- bfc 和ifc
- pull解析XML
- SQLite在多线程环境下的应用
- CreateProcess
- dpkg 删除已安装软件
- 【自己动手写上位机】开篇说明