//
// ViewController.m
// UI_03视图控制器
//
// Created by lanou3g on 17/8/7.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()
@end
@implementation ViewController
/*
// 初始化方法
- (instancetype)init
{
self = [super init];
if (self) {
}
return self;
}
//view的创建
- (void)loadView {
}
*/
#pragma mark - 视图将要出现
- (void)viewWillAppear:(BOOL)animated {
NSLog(@"视图将要出现");
}
#pragma mark - 视图已经出现
- (void)viewDidAppear:(BOOL)animated {
NSLog(@"视图已经出现");
}
#pragma mark - 视图将要消失
- (void)viewWillDisappear:(BOOL)animated {
NSLog(@"视图将要消失");
}
#pragma mark - 视图已经消失
- (void)viewDidDisappear:(BOOL)animated {
NSLog(@"视图已经消失");
}
#pragma mark - 视图加载完成
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(150, 200, 50, 30);
[button setTitle:@"点我" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
button.backgroundColor = [UIColor orangeColor];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
//模态推出í
- (void)buttonAction:(UIButton *)button {
//创建一个要弹出的界面
SecondViewController *secondViewController = [[SecondViewController alloc] init];
// secondViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//参数1:弹出的界面
//参数2:是否以动画的形式弹出
//参数3:界面弹出完成之后要进行的操作
[self presentViewController:secondViewController animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//
// SecondViewController.m
// UI_03视图控制器
//
// Created by lanou3g on 17/8/7.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setTitle:@"返回" forState:UIControlStateNormal];
button1.frame = CGRectMake(150, 150, 50, 30);
button1.backgroundColor = [UIColor orangeColor];
[button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
}
- (void)button1Action:(UIButton *)button1 {
//
[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