UI基础 视图控制器

 

RootViewController

 

#import "RootViewController.h"
#import "SecondViewController.h"
@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"视图已经加载好了,可以用了");
    self.view.backgroundColor=[UIColor redColor];
    UIButton* button=[UIButton buttonWithType:UIButtonTypeSystem];
    button.frame=CGRectMake(10, 100, 100, 50);
    [self.view addSubview:button];
    button.backgroundColor=[UIColor yellowColor];
    [button addTarget:self action:@selector(jump) forControlEvents:UIControlEventTouchUpInside];
    
    
}
-(void)jump
{
//    点击按钮到第二个页面
//    跳到哪
    SecondViewController* second=[[SecondViewController alloc]init];
    
//    怎么跳
    second.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
//
    [self presentViewController:second animated:YES completion:^{
        NSLog(@"跳转完成");
    }];
    
    
    
}

-(void)loadView
{
    
    [super loadView];
    NSLog(@"视图正在加载");
    
}


-(void)viewWillAppear:(BOOL)animated
{
    
    NSLog(@"视图将要出现");
    
}

-(void)viewDidAppear:(BOOL)animated
{
    NSLog(@"视图已经出现");
    
}

-(void)viewWillDisappear:(BOOL)animated
{
    NSLog(@"视图将要消失");
    
}
-(void)viewDidDisappear:(BOOL)animated
{
    NSLog(@"视图已经消失");
}




@end

 

SecondViewController

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor blueColor];
    
    UIButton* button=[UIButton buttonWithType:UIButtonTypeSystem];
    button.frame=CGRectMake(10, 100, 100, 50);
    [self.view addSubview:button];
    button.backgroundColor=[UIColor yellowColor];
    [button addTarget:self action:@selector(jumpback) forControlEvents:UIControlEventTouchUpInside];
    
    
    
}

-(void)jumpback
{
    
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"返回完成");
    }];
}

@end

 

posted @ 2020-07-20 22:25  逆欢  阅读(105)  评论(0编辑  收藏  举报