UI03-试图控制器

ViewController.m

#import "ViewController.h"
#import "SecondViewController.h"

@interface ViewController ()

@end

@implementation ViewController
#pragma mark - 试图将要出现
-(void)viewWillAppear:(BOOL)animated{
    NSLog(@"试图将要出现");

}
//试图已经出现
- (void)viewDidAppear:(BOOL)animated{
    NSLog(@"试图已经出现");
}
//试图将要消失
- (void)viewDidDisappear:(BOOL)animated{
    NSLog(@"试图将要消失");
}
//试图已经消失
- (void)viewWillDisappear:(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(200, 200, 50, 30);
    //button.titleLabel.text =@"hello";
    [button setTitle:@"Hello" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    button.backgroundColor = [UIColor blueColor];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
 }

//模态
-(void)buttonAction:(UIButton *)button{
    //创建一个要弹出的界面
    SecondViewController *secondViewController = [[SecondViewController alloc] init];
    //secondViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
    //1.弹出的界面  2. 是否已动画的形式弹出  3.界面弹出完成之后要进行的操作
    [self presentViewController:secondViewController animated:YES completion:nil];
}


SecondViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor redColor];
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(200, 300, 50, 30);
    //button.titleLabel.text =@"hello";
    [button1 setTitle:@"Hi" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    button1.backgroundColor = [UIColor orangeColor];
    [button1 addTarget:self action:@selector(buttomAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
   }
-(void)buttomAction:(UIButton *)button{
    [self dismissViewControllerAnimated:YES completion:nil];

}


这些都是特别初级的内容,知道大致的原理就可以了哦,新手看吧。
PS:我也是ios菜鸟级别 求同行啊

你可能感兴趣的:(UI03-试图控制器)