IOS开发之页面切换

本文介绍了iOS中四种常见的视图切换方法:addSubview插入新视图、insertSubview定位插入新视图、presentModalViewController模态视图控制器及pushViewController进行导航。每种方法都附带了代码示例和具体说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

从一个ViewController切换到另一个ViewController有下面几种方法:
(1)addsubview方法切换视图
         self.view addSubview:(加载的新页面);
     相应的 [self.view removeFromSuperview];移除添加的view
(2)self.view insertSubview:(加载的新页面) atIndex:n;
对n的解释:页面都是层次叠加的,n表示加载到那一层上面


(3)presentModalViewController方法
        photoNacController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
     photoNacController.modalPresentationStyle = UIModalPresentationFullScreen;
    self presentModalViewController:(加载的新页面) animated:
    modalTransitionStyle用于设置页面切换的动画
     modalPresentationStyle用于设置视图显示的方式
         两种方法试试就知道用途了!
(4) pushViewController 导航
       [self.navigationController pushViewController:(加载的新页面) animated:YES];
      对应的
        [self.navigationController popViewControllerAnimated:YES];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值