视图控制器(入门级)

来源:互联网 发布:淘宝联盟怎么满减 编辑:程序博客网 时间:2024/06/07 14:25
1.创建按钮(第一个视图)

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 100, 100, 50)];

    button.backgroundColor = [UIColor grayColor];

    [self.view addSubview:button];

    [button addTarget:self action:@selector(jump) forControlEvents:UIControlEventTouchUpInside];

2.视图跳转

-(void)jump

{

    firstViewController *first = [[firstViewController alloc] init];

    first.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

    [self presentViewController:first animated:YES completion:^{

        NSLog(@"跳转完成");

    }];

}

3.视图跳回(第二个视图)

    创建按钮

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 100, 100, 50)];

    button.backgroundColor = [UIColor redColor];

    [self.view addSubview:button];

    

    [button addTarget:self action:@selector(jumpBack) forControlEvents:UIControlEventTouchUpInside];


    视图跳回

-(void)jumpBack

{

    [self dismissViewControllerAnimated:YES completion:^{

        NSLog(@"返回完成");

    }];

}

原创粉丝点击