一、打飞机游戏
项目:Homework_Plane_Teacher0309
1.1 添加标签 #pragma mark 1.创建两张地图,实现地图的移动
1.2 代码的封装
1.2.1 //TODO:
1.2.2 #pragma mark
二、视图控制器
项目:ViewController0309
2.1 AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[self.window rootViewController];
//视图控制器的
//作用:管理视图
//视图控制器内部 有一个自带的view
//1.创建视图控制器的一个子类
//2.实例化一个视图控制器的对象
//firstVC:是一个抽象的管理者,不可见。
_firstVC = [[FirstViewController alloc]init];
//把firstVC设置为window的根视图控制器,
//就相当于将firstVC.view添加到window上
//即:[self.window addSubview:firstVC.view];
//视图控制器加载view的模式:懒加载模式(当你使用视图控制器的时候,才会加载view)
self.window.rootViewController = _firstVC;
return YES;
}
2.2 FirstViewController.m
//视图已经加载成功
//注意:这个方法在视图控制器的整个生命周期中只会调用一次
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(100, 100, 60, 40);
btn.backgroundColor = [UIColor redColor];
[btn setTitle:@"下一页" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
//下一页按钮
- (void)click:(UIButton *)button
{
SecondViewController *secondVC = [[SecondViewController alloc]init];
//找到window window是 APPDelegate类的属性
//1.先找到“应用程序类”(单例类)的对象
//即UIApplication的对象
//单例类:在此应用程序中只有一个对象
UIApplication *app = [UIApplication sharedApplication];
//2.找入口类的对象
//即AppDelegate的对象
//就是UIApplication的对象的"代理协议"
//即app.delegate
AppDelegate *appDelegate = app.delegate;
//3.获取window
UIWindow *window = appDelegate.window;
window.rootViewController = secondVC;
}
//只要view要显示出来
//就会调用两个方法:视图将要显示和视图已经显示
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
//视图已经显示
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
2.3 SecondViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
//添加返回按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(100, 100, 60, 40);
btn.backgroundColor = [UIColor grayColor];
[btn setTitle:@"返回" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
- (void)click
{
FirstViewController *firstVC = [[FirstViewController alloc]init];
//1.找application
UIApplication *app = [UIApplication sharedApplication];
//2.获得APPDelegate类对象
AppDelegate *appDelegate = app.delegate;
//3.获取window
UIWindow *window = appDelegate.window;
//获取FirstViewController
window.rootViewController = firstVC;
}