// 系统要进行初始化
- (void)loadView {
[super loadView];
NSLog(@"%s",__func__);
}
// 进一步初始化界面
- (void)viewDidLoad {
NSLog(@"%s",__func__);
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
// self 用来调用控制部分的功能
// self.view 用来调用视图部分的功能
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button1.frame = CGRectMake(10, 100, 300, 30);
button1.tag = 101;
button1.backgroundColor = [UIColor cyanColor];
[button1 addTarget: self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
// 加到视图控制器的视图上
[self.view addSubview:button1];
NSLog(@"%.1f %.1f",self.view.frame.origin.x,self.view.frame.origin.y);
NSLog(@"%.1f %.1f",self.view.frame.size.width,self.view.frame.size.height);
// NSString *path = [NSString stringWithFormat:@"%@/Library/Caches/demo.plist",NSHomeDirectory()];
// NSLog(@"%@",NSHomeDirectory());
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"%s",__func__);
}
// 视图已经显示在屏幕上时调用
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"%s",__func__);
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
NSLog(@"%s",__func__);
}
// 视图已经出屏幕时调用
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
NSLog(@"%s",__func__);
}
//- (void)viewDidUnload {
// [super viewDidUnload];
// NSLog(@"%s",__func__);
//}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - button Action
- (void)buttonAction:(UIButton *)button {
NSLog(@"button %ld is clicked",button.tag);
/**
* 视图控制器跳转
*
* MainVC - > SecondVC
*/
// 1. 实例化要跳转的界面对象
SecondViewController *secondVC = [[SecondViewController alloc] init];
// 1.5 设置模式
// UIModalTransitionStyleCrossDissolve 渐变
// UIModalTransitionStyleFlipHorizontal 横向翻转
// UIModalTransitionStylePartialCurl 翻书
secondVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
// 2.进行模式对话窗体跳转
[self presentViewController:secondVC animated:YES completion:^{
// 当跳转动画完成时的回调
NSLog(@"跳转完成");
NSLog(@"%.1f %.1f",self.view.frame.origin.x,self.view.frame.origin.y);
NSLog(@"%.1f %.1f",self.view.frame.size.width,self.view.frame.size.height);
}];
}
// 两加载
//- (void)loadView;
//- (void)viewDidLoad;
// 两进
//- (void)viewWillAppear:(BOOL)animated;
//- (void)viewDidAppear:(BOOL)animated;
// 两出
//- (void)viewWillDisappear:(BOOL)animated;
//- (void)viewDidDisappear:(BOOL)animated;
// 两释放
//- (void)viewWillUnload;
//- (void)didReceiveMemoryWarning;<pre name="code" class="objc">- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/**
视图控制器 UIView + UIResponder
有 视图部分 和 控制部分 两方面组成
MVC - Model View Controller
通过控制部分将数据模型绑定在视图上
低耦合度 关联小 条理清晰
*/
MainViewController *mainVC = [[MainViewController alloc] init];
// 根视图控制器 rootVC 第一个显示的叫做根视图控制器
self.window.rootViewController = mainVC;
return YES;
}
UIViewController
最新推荐文章于 2015-09-28 20:39:53 发布