iOS View 生命周期

释放双眼,带上耳机,听听看~!

现在来看看View的生命周期

显示过程

-(void)willMoveToSuperview:(UIView *)newSuperview
-(void)didMoveToSuperview

-(void)willMoveToWindow:(UIWindow *)newWindow
-(void)didMoveToWindow

-(void)layoutSubviews

移除过程

-(void)willMoveToSuperview:(UIView *)newSuperview
-(void)willMoveToWindow:(UIWindow *)newWindow

-(void)didMoveToWindow
-(void)didMoveToSuperview

-(void)dealloc

验证
#import "TestView.h"

@implementation TestView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self){
        NSLog(@"initWithFrame");
    }
    return self;
}

//(superview)
- (void)willMoveToSuperview:(UIView *)newSuperview{
     NSLog(@"willmovetosuperview");
    [super willMoveToSuperview:newSuperview];
}

- (void)didMoveToSuperview{
    NSLog(@"didmovetosuperview");
    [super didMoveToSuperview];
}

//(window)
- (void)willMoveToWindow:(UIWindow *)newWindow{
     NSLog(@"willmovetowindow");
    [super willMoveToWindow:newWindow];
}

- (void)didMoveToWindow{
     NSLog(@"didmovetowindow");
    [super didMoveToWindow];
}

- (void)layoutSubviews
{
    NSLog(@"layoutSubviews");
    [super layoutSubviews];
}


- (void)removeFromSuperview{
    NSLog(@"layoutSubviews");
    [super removeFromSuperview];
}

- (void)dealloc{
    NSLog(@"dealloc");
}

@end

 

人已赞赏
iOS文章

iOS开发创建Framework包

2019-12-5 12:48:48

iOS文章

iOS 制作自己的Cocoapod

2019-12-5 13:20:51

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索