标签:
1 #import "ViewController.h" 2 #import "SecondViewController.h" 3 4 @interface ViewController () 5 6 @end 7 8 @implementation ViewController 9 10 11 // 视图控制器的生命周期 12 // 视图控制器的加载方法 13 // 模态视图方法 14 15 /* 16 // 视图控制器的加载方法 17 - (instancetype)init 18 { 19 self = [super init]; 20 if (self) { 21 // 属性、成员变量 22 // 千万不要在这个地方初始化控件 23 } 24 return self; 25 } 26 27 - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 28 { 29 // 初始化控件(用nib文件创建的控件) 30 // IB (.Xib文件) 没有stroyboard之前用的 这个文件叫nib文件 31 } 32 33 - (void)loadView 34 { 35 //初始化试图用 36 } 37 */ 38 39 40 // 视图加载完成时调用,视图控制器当中(伪第一)调用的方法 41 - (void)viewDidLoad { 42 [super viewDidLoad]; 43 NSLog(@"viewDidLoad"); 44 45 self.view.backgroundColor = [UIColor cyanColor]; 46 47 UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; 48 [btn setFrame:CGRectMake(130, 100, 100, 100)]; 49 [btn setTitle:@"next" forState:UIControlStateNormal]; 50 [btn setBackgroundColor:[UIColor orangeColor]]; 51 [btn addTarget:self action:@selector(modelMethod) forControlEvents:UIControlEventTouchUpInside]; 52 [self.view addSubview:btn]; 53 54 } 55 #pragma mark - life Cycle 56 // 视图(每次)将要出现的时候调用 57 - (void)viewWillAppear:(BOOL)animated 58 { 59 [super viewWillAppear:animated]; 60 NSLog(@"viewWillAppear"); 61 62 } 63 // 视图(每次?)出现完成的时候调用 64 - (void)viewDidAppear:(BOOL)animated 65 { 66 [super viewDidAppear:animated]; 67 NSLog(@"veiwDidAppear"); 68 69 } 70 // 视图(每次)将要消失的时候调用 71 - (void)viewWillDisappear:(BOOL)animated 72 { 73 [super viewWillDisappear:animated]; 74 NSLog(@"viewWillDisappear"); 75 76 } 77 // 视图消失完成之后时候调用 78 -(void)viewDidDisappear:(BOOL)animated 79 { 80 [super viewDidDisappear:animated]; 81 NSLog(@"viewDidDisappear"); 82 83 } 84 85 #pragma mark - Model View Method(模态视图方法) 86 - (void)modelMethod 87 { 88 // 视图切换,切换到下一个视图 89 SecondViewController *secondVC = [[SecondViewController alloc] init]; 90 secondVC.modalTransitionStyle = UIModalTransitionStylePartialCurl; 91 92 // 进入一个视图 93 [self presentViewController:secondVC animated:YES completion:nil]; 94 95 96 } 97 98 #pragma mark - other System Method 99 - (void)didReceiveMemoryWarning { 100 [super didReceiveMemoryWarning]; 101 } 102 103 @end
1 #import "SecondViewController.h" 2 3 @interface SecondViewController () 4 5 @end 6 7 @implementation SecondViewController 8 9 - (void)viewDidLoad { 10 [super viewDidLoad]; 11 NSLog(@"viewDidLoad"); 12 13 self.view.backgroundColor = [UIColor darkGrayColor]; 14 15 UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; 16 [btn setFrame:CGRectMake(130, 100, 100, 100)]; 17 [btn setTitle:@"back" forState:UIControlStateNormal]; 18 [btn setBackgroundColor:[UIColor whiteColor]]; 19 [btn addTarget:self action:@selector(backMethod) forControlEvents:UIControlEventTouchUpInside]; 20 [self.view addSubview:btn]; 21 22 } 23 - (void)backMethod 24 { 25 // 返回上一个视图 26 [self dismissViewControllerAnimated:YES completion:nil]; 27 } 28 29 - (void)didReceiveMemoryWarning { 30 [super didReceiveMemoryWarning]; 31 }
标签:
原文地址:http://www.cnblogs.com/oc-bowen/p/5082002.html