【UIViewController视图控制器】

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/winer888/article/details/49361647

#import "ViewController.h"

#import "otherViewController.h"//导入


@interface ViewController ()


@end


@implementation ViewController

//加载视图内存 一定要用父类的加载视图初始化 不然会一直加载内存 知道崩溃

-(void)loadView

{

    [super loadView];

     NSLog(@"加载内存");

}

//视图内存加载完成

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor=[UIColor greenColor];

    

    UITextField *text=[[UITextField alloc]initWithFrame:CGRectMake(1108011040)];

    text.backgroundColor=[UIColor redColor];

    [self.view addSubview:text];

    

    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(110130 , 11040)];

    [btn setTitle:@"shift" forState:UIControlStateNormal];

    btn.backgroundColor=[UIColor redColor];

    [btn addTarget:self action:@selector(shiftTap) forControlEvents:UIControlEventTouchUpInside];

    

    [self.view addSubview:btn];

    NSLog(@"加载完成");

}

-(void)shiftTap//界面切换

{// 为了看完整的生命周期 再创建一个视图控制器 因为显示另一个控制器的视图时 起始的那个视图就会产生 将要消失 和已经消失两个阶段

    otherViewController *other=[[otherViewController alloc]init];

    //原来有些代码可以一次性顺理打出来

    other.view=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"start2.jpeg"]];

    //模态 呈现 animated意思是是否用动画效果

    [self presentViewController:other animated:YES completion:nil];

    /*UIImage *vv=[UIImage imageNamed:@"start2.jpeg"];

    self.view=[[UIImageView alloc]initWithImage:vv];

    return self.view;*/

}

//视图将要显示

-(void)viewWillAppear:(BOOL)animated

{

 NSLog(@"显示");

}

//视图已经显示

-(void)viewDidAppear:(BOOL)animated

{

    NSLog(@"已经显示");


}

//视图将要消失

-(void)viewWillDisappear:(BOOL)animated

{

    NSLog(@"消失");

}

//视图已经消失

-(void)viewDidDisappear:(BOOL)animated

{

    NSLog(@"已经消失");

}

//内存报警 内存爆满时才会显示

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

    NSLog(@"内存爆满");

}


@end

猜你喜欢

转载自blog.csdn.net/winer888/article/details/49361647