首页 > 代码库 > 模态视图 push pop

模态视图 push pop

导航控制器用来管理一组具有层级关系的视图控制器,进入下一个界面的方式是push,返回是pop.   (层级关系:后一个界面显示的内容依赖于前一个界面)

当没有层级关系的视图控制器之间切换时(比如:前一个界面显示的内容依赖于后一个界面).要使用模态视图,进入下一个界面的方式是present,返回是dismiss.

模态视图:

- (IBAction)pressButton:(UIButton *)btn

{

    FirstDetailViewController *firstDetailVC = [[FirstDetailViewController alloc] init];

    firstDetailVC.modalTransitionStyle =UIModalTransitionStyleFlipHorizontal;

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

        NSLog(@"Tsummer");

    }];

}

- (IBAction)pressDetailButton:(UIButton *)sender

{

    [self dismissViewControllerAnimated:YES completion:^{

        NSLog(@"Tsummer");

    }];

}


系统提供的页面切换的效果:

typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {

    UIModalTransitionStyleCoverVertical = 0,  //从底部划入

    UIModalTransitionStyleFlipHorizontal,  //水平翻转

    UIModalTransitionStyleCrossDissolve,  //交叉溶解

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2

    UIModalTransitionStylePartialCurl,  //翻页效果

#endif

};

push推出

- (IBAction)pressButton:(UIButton *)btn

{

    FirstDetailViewController *firstDetailVC = [[FirstDetailViewController alloc] init];

    [self.navigationController pushViewController:firstDetailVC animated:YES];

}

- (IBAction)pressDetailButton:(UIButton *)sender

{

    [self.navigationController popViewControllerAnimated:YES];//pop上一界面

   // [self.navigationController popToRootViewControllerAnimated:YES];//pop主视图控制器界面

   // [self.navigationController popToViewController:(UIViewController *) animated:YES];//当存在多个页面时,自定义pop到哪一个页面

}







模态视图 push pop