[iOS开发] present 和 push
程序员文章站
2022-07-05 21:34:09
一、基本概念共同点– present和push方法都可用于推出新的界面。 present和dismiss对应使用,push和pop对应使用。不同点– present弹出的视图是模态视图(我对模态视图的理解大概就是一个临时视图);push由视图栈控制,每一个视图都入栈,调用之前的视图则需要出栈– present只能逐级返回;push可返回任意一层二、使用方法用UINavigationController的时候使用pushViewController:animated----返回之前的视图[...
一、基本概念
共同点
– present和push方法都可用于推出新的界面。 present和dismiss对应使用,push和pop对应使用。
不同点
– present弹出的视图是模态视图(我对模态视图的理解大概就是一个临时视图);push由视图栈控制,每一个视图都入栈,调用之前的视图则需要出栈
– present只能逐级返回;push可返回任意一层
二、使用方法
-
用UINavigationController的时候使用pushViewController:animated
----返回之前的视图[[self navigationController] popViewControllerAnimated:YES];
—ps:push以后会在navigation的left bar自动添加back按钮,它的响应方法就是返回。所以一般不需要写返回方法,点back按钮即可。 -
其他时候用presentModalViewController:animated
[self presentModalViewController:controller animated:YES];//YES有动画效果
-----返回之前的视图 [self dismissModalViewControllerAnimated:YES];
三、页面的push/present的demo
给second界面创建一个导航栈控制器 可以保证等会push的实现
第一个界面present第二个界面
//第一个界面的按下跳转 使用present
-(void)press{
SecondViewController *secondView = [[SecondViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:secondView];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:nav animated:YES completion:nil];
}
第二个界面push第三个界面
//第二个界面的返回按钮与按下push一个新的界面
-(void)back{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)push{
ThirdViewController *thirdView = [[ThirdViewController alloc]init];
[self.navigationController pushViewController:thirdView animated:YES];
}
//第三个界面的back 如果是dismiss那么就返回第一个界面 如果是pop那么就是第二个界面
- (void)back{
// [self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popViewControllerAnimated:YES];
}
本文地址:https://blog.csdn.net/m0_46110288/article/details/108740633
推荐阅读
-
IOS开发(74)之把 Array 和 Dictionaries 序列化成 JSON 对象
-
iOS开发- runtime基本用法解析和用runtime给键盘添加工具栏和按钮响应事件
-
在iOS开发的Quartz2D使用中实现图片剪切和截屏功能
-
简介iOS开发中应用SQLite的模糊查询和常用函数
-
iOS开发中使用UIScrollView实现图片轮播和点击加载
-
iOS开发中Quartz2D控制圆形缩放和实现刷帧效果
-
iOS开发中使用Quartz2D绘制上下文栈和矩阵的方法
-
IOS开发使用KeychainItemWrapper 持久存储用户名和密码
-
详解iOS开发中的转场动画和组动画以及UIView封装动画
-
讲解iOS开发中对音效和音乐播放的简单实现