UI3

it2024-11-02  12

// // SecondViewController.h // UI3_UIViewController生命周期 // // Created by zhangxueming on 15/7/2. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <UIKit/UIKit.h> @interface SecondViewController : UIViewController @end // // SecondViewController.m // UI3_UIViewController生命周期 // // Created by zhangxueming on 15/7/2. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "SecondViewController.h" @interface SecondViewController () @end @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(50, 400, self.view.frame.size.width-100, 50); btn.backgroundColor = [UIColor whiteColor]; [btn setTitle:@"视图模式跳转-First" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; self.view.backgroundColor = [UIColor cyanColor]; } - (void)btnClicked { if ([self.view superview]) { NSLog(@"123"); [self.view superview].backgroundColor=[UIColor redColor]; [self.view removeFromSuperview]; } //使消失当前视图控制器视图 //[self dismissViewControllerAnimated:YES completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end

 

// // ViewController.m // UI3_UIViewController生命周期 // // Created by zhangxueming on 15/7/2. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "ViewController.h" #import "SecondViewController.h" @interface ViewController () @end @implementation ViewController //视图控制器 //当一个视图控制器被创建,并在屏幕上显示的时候。 代码的执行顺序 //1、 alloc                                   创建对象,分配空间 //2、init (initWithNibName) 初始化对象,初始化数据 //3、loadView                          从nib载入视图 ,通常这一步不需要去干涉。除非你没有使用xib文件创建视图 //4、viewDidLoad                   载入完成,可以进行自定义数据以及动态创建其他控件 //5、viewWillAppear              视图将出现在屏幕之前,马上这个视图就会被展现在屏幕上了 //6、viewDidAppear               视图已在屏幕上渲染完成 //当一个视图被移除屏幕并且销毁的时候的执行顺序,这个顺序差不多和上面的相反 //1、viewWillDisappear            视图将被从屏幕上移除之前执行 //2、viewDidDisappear             视图已经被从屏幕上移除,用户看不到这个视图了 //3、dealloc                           视图被销毁,此处需要对你在init和viewDidLoad中创建的对象进行释放 - (void)loadView { [super loadView]; NSLog(@"开始加载视图"); } - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"视图加载完成"); // Do any additional setup after loading the view, typically from a nib. //UIViewController UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(50, 100, self.view.frame.size.width-100, 50); btn.backgroundColor = [UIColor whiteColor]; [btn setTitle:@"视图模式跳转-Second" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; self.view.backgroundColor= [UIColor redColor]; } - (void)btnClicked { SecondViewController *svc = [[SecondViewController alloc] init]; //设置跳转模式 //UIModalTransitionStylePartialCurl 翻页效果 svc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //显示视图控制器中的view [self presentViewController:svc animated:YES completion:nil]; } //视图将要显示 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSLog(@"Appering 视图将要显示"); } //视图已经显示 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSLog(@"Appeared 视图已经显示"); } //视图将要消失 - (void)viewWillDisappear:(BOOL)animated { NSLog(@"Disappearing 视图将要消失"); } //视图已经消失 - (void)viewDidDisappear:(BOOL)animated { NSLog(@"Disappeared 视图消失"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

 

转载于:https://www.cnblogs.com/0515offer/p/4638573.html

最新回复(0)