iOS 第9课 导航视图 NavigationView

iOS 16.2 在 SwiftUI 子视图中无法关闭弹出的(sheet)导航视图(NavigationView)之解决 在本篇博文中,我们讨论了 iOS 16.2 里 SwiftUI 弹出(sheet)的导航视图 A 中的子视图无法关闭视图 A 自身的问题,随即提出解决方法并让子视图在 Xcode 预览(preview)中可以显示。 阅读详情

导航视图和android 中的viewpager类似

//导航栏相关的是navigationItem,控制器相关的是navigationController




0: 首先还是通过纯的代码来实现

0:删除3个文件ViewController.h,ViewController.m,Main.storyboard

1:修改点击左边的蓝色按钮,然后选择general-》developer info-》main interface ,将这个main interface 晴空

1: 修改appdeleget

//
//  AppDelegate.m
//  NineNavigationDemo
//
//  Created by 千雅爸爸 on 16/10/15.
//  Copyright © 2016年 kodulf. All rights reserved.
//

#import "AppDelegate.h"
#import "FirstViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];
    
       FirstViewController *firstViewController = [[FirstViewController alloc]init];
    UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:firstViewController];
    [self.window setRootViewController:navigationController];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end



2: 创建三个控制器,

2.1: 第一个控制器:

//
//  FirstViewController.m
//  NineNavigationDemo
//
//  Created by 千雅爸爸 on 16/10/15.
//  Copyright © 2016年 kodulf. All rights reserved.
//

#import "FirstViewController.h"
#import "SecondViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad {
    //导航栏的坐标是(0,20,宽度,44);
    
    //导航栏相关的是navigationItem,控制器相关的是navigationController

    [super viewDidLoad];
    [self setTitle:@"第一页"];
    [self.view setBackgroundColor:[UIColor greenColor]];//
    UIBarButtonItem *item =[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL];
    //设置导航的item
    self.navigationItem.rightBarButtonItem = item;
    
    //自定义view作为导航的菜单
    UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [itemButton setTitle:@"UIButton" forState:UIControlStateNormal];
    [itemButton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
    [itemButton setFrame:CGRectMake(0,0,100,100)];
    
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithCustomView:itemButton];
    
    //设置多个button
    self.navigationItem.leftBarButtonItems = @[item,item2];
    
    //设置导航蓝上面的颜色
    self.navigationController.navigationBar.backgroundColor = [UIColor blueColor];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"background"] forBarMetrics:UIBarMetricsCompact];//后面的是图片的渲染的样式的。
    //UIBarMetricsDefault默认的,背景的图片和颜色是不能重复的,像这里图片会覆盖颜色的
    //UIBarMetricsCompac 会使用图片的颜色
    
    
    //注意了,这里的尺寸里面的位置,
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"Push" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    [button setBackgroundColor:[UIColor blackColor]];
    [button setFrame:CGRectMake(100,80,100,100)];
    [button addTarget:self action:@selector(pushController) forControlEvents:UIControlEventTouchUpInside];//当在内部点击的时候触发

    [self.view addSubview:button];
    
    //导航栏控制器在控制多个视图控制的时候的跳转
    

    // Do any additional setup after loading the view.
}
//相当于入战的操作

-(void) pushController{
    NSLog(@"点击了first");
    [self.navigationController pushViewController:[[SecondViewController alloc]init] animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

2.2 第二个控制器

//
//  SecondViewController.m
//  NineNavigationDemo
//
//  Created by 千雅爸爸 on 16/10/15.
//  Copyright © 2016年 kodulf. All rights reserved.
//

#import "SecondViewController.h"
#import "FirstViewController.h"
#import "ThirdViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    //导航栏相关的是navigationItem,控制器相关的是navigationController
    
    [super viewDidLoad];
    //默认的切换的时候是有一些卡顿的。
    [self.view setBackgroundColor:[UIColor yellowColor]];
    [self setTitle:@"第二页"];
    //多个子控制器对象是公用一个导航条的
    
    //添加统一的返回按钮,简单的就是一个子
    UIBarButtonItem *leftItem =[[UIBarButtonItem alloc] initWithTitle:@"回退" style:UIBarButtonItemStylePlain target:self action:@selector(popController)];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    
    UIBarButtonItem *rightItem =[[UIBarButtonItem alloc]initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(pushController)];
    
    // Do any additional setup after loading the view.
    
    self.navigationItem.rightBarButtonItem = rightItem;
    //公用一套导航条的
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
}

-(void )popController{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)pushController{
    [self.navigationController pushViewController:[[ThirdViewController alloc]init] animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

2.3: 第三个控制器

//
//  ThirdViewController.m
//  NineNavigationDemo
//
//  Created by 千雅爸爸 on 16/10/15.
//  Copyright © 2016年 kodulf. All rights reserved.
//

#import "ThirdViewController.h"

@interface ThirdViewController ()

@end

@implementation ThirdViewController

- (void)viewDidLoad {
    //导航栏相关的是navigationItem,控制器相关的是navigationController
    
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //pop跳转的时候,可以跳转到上一个,也可以跳转到根,也可跳转到指定的
    [self setTitle:@"第三个"];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"返回上一层或者最上层" style:UIBarButtonItemStylePlain target:self action:@selector(popViewController)];
    //导航栏相关的是navigationItem,控制器相关的是navigationController
    
    self.navigationItem.leftBarButtonItem = leftItem;
    
}
-(void)popViewController{
    //可以跳转到第一页,也可以跳转到上一页
    //[self.navigationController popViewControllerAnimated:YES];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end






Apple 已弃用 NavigationView,使用 NavigationStack 和 NavigationSplitView 实现 SwiftUI 导航 Apple 已弃用 NavigationView,它以前被用作封装视图堆栈,这些视图本质上是在呈现时推送并在关闭时弹出的视图。这是 iOS 导航从一开始就使用的熟悉方式,没有物理后退按钮,但顶部有一个导航栏,有一个后退按钮,描述了“后退”的位置。有两种实现导航的新方法,但它们最终在 iPhone 上看起来非常相似,原因我将在后面讨论。让我们开始吧!这个应用程序非常简单地从几个Hashable和Identifiable结构开始。Screen存储导航状态的枚举必须是Hashable,因为新的初始化程序需要Nav 阅读详情

相关推荐

UINavigationController自定义

iOS UINavigationController自定义,push动画效果

iOS开发(Swift):创建UINavigationView的三种方法

UINavigationController是iOS开发中很常用的一种组件,由于种种原因许多人喜欢从代码创建视图控件,包括UINavigationController,但是有时候我们的屏幕控件太多,一方面使用storyboard可以方便设计,但是另一方面又需要用代码创建UINavigationController来灵活控制程序运行,下面将分别介绍代码,IB和两者结合创建一个UINavigati...

keZhenxu 566

Android使用导航视图NavigationView的代码例子

Android使用导航视图NavigationView的代码例子。用于演示结合DrawerLayout与NavigationView实现侧滑菜单的功能,并给出了自定义导航视图的一个例子。

SwiftUI中NavigationStack使用以及与NavigationView的区别(NavigationLink,navigationDestination,NavigationPath)

在iOS开发中,导航视图无疑是最常用的组件之一。当SwiftUI首次发布时,它附带了一个名为NavigationView的视图,用于构建基于导航的用户界面。随着iOS 16的发布,苹果已经弃用了旧的导航视图,并引入了一个名为NavigationStack的新视图来呈现视图堆栈。最重要的是,开发人员可以利用这个新视图来构建数据驱动的导航。

郭永明的技术专栏 3764

433MHz无线通信避坑指南:如何解决信号干扰和误码问题

本文深入探讨433MHz无线通信中的信号干扰和误码问题,提供从射频前端设计到协议优化的全链路解决方案。通过天线匹配、电源噪声抑制、曼彻斯特编码改进及实时频点切换等技术,显著提升通信稳定性和距离。适合智能家居和工业无线控制系统的开发者参考。

weixin_29288313的博客 415

别再为STM32F407的USB高速通信发愁了!手把手教你用USB3320(ULPI接口)搞定硬件设计

本文详细介绍了STM32F407通过USB3320(ULPI接口)实现高速USB通信的硬件设计实战。从USB3320的选型优势到原理图设计避坑,再到PCB布局和固件配置,提供了一套完整的解决方案。特别针对USB PHY芯片的常见问题,如供电处理、信号完整性和初始化代码,给出了专业建议和调试技巧,帮助工程师高效完成高速USB通信设计。

weixin_42527401的博客 387

推荐文章:简化导航的艺术——NavigationView

推荐文章:简化导航的艺术——NavigationView 项目介绍 在构建优雅且用户友好的iOS应用时,导航的流畅性是不可忽视的关键。Mijick团队深知这一点,因此推出了开源库—NavigationView。这不仅仅是一个导航解决方案,它是一套为SwiftUI量身定做的工具包,旨在让开发者以最少的代码实现高效、美观的页面跳转和导航管理。 技术分析 NavigationView的核心亮点在于其高度...

gitblog_00894的博客 348

基于ANSYS的电磁兼容仿真教程

最近,在做某系统的EMC仿真,使用ANSYS套件,对仿真学习做简要记录。本书简介与目录如下:本书配套有:视频教程+工程源文件+彩色仿真图片,下载链接如下:(审核中)第1章 基础知识1.1 电磁兼容基础​​​MS2、EMC三要素:3、 国际无线电干扰特别委员会标准:CISPR标准4、电磁兼容测试认证:传导发射(CE)、传导敏感度(CS)、辐射发射(RE)和辐射敏感度(RS)测试。

weixin_42508010的博客 2051

SwiftUI中NavigationView的使用

在本章中,你会学会使用SwiftUI中NavigationView

王偃飞的博客 1123

资产监测设备中130dBm的GPS信号注入天线端口,C/N0一般是多少?

笔者的团队一直从事于资产监测设备的开发,在开发过程中,涉及到很多细节的问题,针对新入职的同事来说较为陌生。同时,在团队外,还有需要对智能硬件终端开发感兴趣的用户。基于此背景下,笔者将在下面的内容主要介绍资产监测设备以及对设备中的GPS相关的问题:130dBm的GPS信号注入天线端口,C/N0一般是多少?作出详细的解答。 资产监测设备概述: 资产监测设备是基于物联网通信技术基础上的智能硬件终端,其主要作用是帮助用户监测资产在仓库、运输途中、交付整个流通环节中,提供资产的实时位置与状态参数。用户只需要登录资产

瑞奇聊通信模组 1229

Tesseract OCR识别不准?手把手教你用PyAutoGUI提升自动点击脚本的准确率

本文针对Tesseract OCR在屏幕自动化中识别不准的问题,提供了一套完整的优化方案。通过PyAutoGUI精准截图、结合PIL和OpenCV进行图像预处理(如灰度化、对比度增强、自适应二值化),并调优Tesseract参数(如PSM模式、白名单),显著提升文本识别准确率。文章还介绍了结合模板匹配、构建容错循环等进阶技巧,帮助开发者打造高可靠性的自动点击脚本。

weixin_29093017的博客 544

【SwiftUI入门练中学】第4课 列表与导航

本课聚焦从“一屏内容”到“多屏应用”的跃迁,通过 List、ForEach、Identifiable 等核心组件,构建支持滑动删除、拖动排序、搜索分组的待办清单与联系人列表。掌握 NavigationStack 与 NavigationLink 实现栈式导航,理解数据→视图→操作→刷新的单向闭环,建立“数据驱动界面”的开发思维,实现高效、流畅的多屏交互体验。

jackchuanqi的博客 72

跟着Synopsys报告,一步步拆解车规芯片FMEDA计算(含公式与避坑点)

本文详细解析了车规芯片FMEDA计算的全流程,基于Synopsys报告拆解实战指南,涵盖基础失效率建模、安全机制效能评估及安全指标合成等关键步骤。通过公式解析、数据准备清单和避坑点分享,帮助工程师掌握ISO26262标准下的硬件量化分析技术,提升车载系统设计可靠性。

weixin_30460489的博客 195

【Swift】第9周 小说列表展示案例

文章目录1. 使用 GeometryReader 调整尺寸2. 滚动视图 ScrollView3. NavigationLink4. 使用 Codable 对多层级的 JSON 进行压缩5. 扩展Bundle6.案例 1. 使用 GeometryReader 调整尺寸 .resizable() 设置图片尺寸是可以被调整的 .frame(width:300, height: 300) 调整图片尺寸 ...

Java 1138

AI Agent Harness Engineering 开发效率工具:Prompt工程、调试与监控平台

随着AI Agent技术从原型探索走向企业级落地,开发者普遍面临Prompt迭代无版本管控、Agent执行黑盒无法定位错误、上线后无监控导致故障频发、多团队协作效率低下四大核心痛点,据2024年LLMOps行业报告显示,没有配套工具链的Agent开发团队平均迭代周期是有工具链团队的6倍,线上故障率高达23%,平均资源浪费超过60%。

小白菜的博客 425

(王道408考研操作系统)第一章计算机系统概述-第三节2:中断和异常

注意!!! 本节内容和《计算机组成原理》中的中断有重合,如果需要详细了解的话可以点击链接跳转:(计算机组成原理)第七章输入和输出系统-第四节2:I/O方式之程序中断方式 为了内容完整,部分内容会借用上述文章 文章目录一:中断和异常的基本概念(1)中断和异常的定义 一:中断和异常的基本概念 在操作系统引入核心态和用户态这两种工作状态后,就需要考虑两种状态之间是如何切换的。 操作系统内核工作在核心态,用户程序工作在用户态,系统不允许用户程序使用核心态的功能,但是用户程序为了完成某些操作又必须使用这些功能

快乐江湖的博客 3530

swiftui-ui-patterns - macos-settings

在构建由 SwiftUI 的Settings场景支持的 macOS 设置窗口时使用。

小青蛙电气 168

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

android 导航抽屉_Android应用程序和材质设计入门:工具栏和导航抽屉

android 导航抽屉 材料设计是Google建立的一套规则,可指导如何开发Android应用。 它们不仅可以应用于Android应用程序,还可以应用于网站设计。 在开发应用程序的过程中,Android提供了一些库来帮助开发人员实施主要的材料准则。 最重要的库是: com.android.support:appcompat-v7:23.0.1 com.android.support...

172

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

QGroundControl 源码导航实战指南:从顶层 UI 到具体实现的快速定位方法

QGC(QGroundControl)是一个横跨 Android、iOS、macOS、Linux 与 Windows 的大型开源地面站项目,其源码体量庞大——仅 `src/` 目录就包含几十个功能模块、上千个 QML/C++ 文件。面对这样的大代码库,如何快速找到"某个界面功能"对应的源码实现,是每个想要二次开发或深入研究的开发者首先要解决的问题。本篇指南以 QGC 官方开发者文档《Navigat

gitblog_00723的博客 218

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

SwiftUI-Cheat-Sheet:10个快速入门SwiftUI的必备技巧与实战指南

SwiftUI是苹果推出的创新UI框架,让开发者能够使用简洁的Swift代码构建跨平台的用户界面。本指南将通过10个实用技巧,帮助你快速掌握SwiftUI 2.0的核心概念和实战技能,从基础布局到高级交互,轻松开启iOS、macOS、watchOS和tvOS应用开发之旅。 [![SwiftUI标志](https://raw.gitcode.com/gh_mirrors/sw/SwiftUI-Ch

gitblog_00519的博客 638

SwiftUI入门终极指南:10个声明式UI开发实践技巧快速掌握

SwiftUI是苹果公司在2019年推出的革命性UI框架,它为iOS开发带来了全新的声明式编程范式。对于iOS开发者来说,掌握SwiftUI意味着能够更快速、更直观地构建用户界面,同时享受更好的代码可维护性和开发效率。TimLiu-iOS项目中收集了大量优秀的SwiftUI资源和实践案例,为开发者提供了宝贵的学习资料。 [![SwiftUI开发图谱](https://raw.gitcode.co

gitblog_00516的博客 1020

SwiftUI-Agent-Skill核心拆解:9大审查维度让AI告别低级SwiftUI错误

如果你正用 Claude Code、Codex 或 Cursor 这类 AI 编程助手写 SwiftUI 代码,大概率踩过这些坑:AI 悄悄用了过时的 API、写出对 VoiceOver 完全"隐身"的按钮,或者埋下意想不到的性能隐患。**SwiftUI-Agent-Skill** 就是一个专为 SwiftUI 打造的 AI 代码审查工具,它用 9 大审查维度系统性地揪出 AI 常犯的低级错误,让

gitblog_00623的博客 408

为什么AI助手写的SwiftUI总是踩坑?SwiftUI-Agent-Skill用9大规则精准纠偏

用 Claude Code、Codex、Cursor 等 AI 助手写 SwiftUI 时,你是否也遇到过这些糟心事:代码用了早已弃用的 API、图标按钮对 VoiceOver 完全不可见、运行起来还有各种意想不到的性能卡顿?**SwiftUI-Agent-Skill** 是一款面向 AI 编程助手的免费 SwiftUI Agent Skill(技能包),它把 9 大规则浓缩成 AI 可执行的检查

gitblog_01032的博客 1058

iOS开发十年演进:从UIKit到SwiftUI与AI时代的生存指南

在移动开发领域,iOS生态的每一次系统迭代都牵动着开发者技术栈的变迁。从早期的Objective-C与UIKit,到Swift语言的逐步成熟,再到SwiftUI与跨平台方案的崛起,开发者需要理解底层运行机制、并发模型与内存管理等核心原理,方能应对复杂工程场景下的性能优化与稳定性治理。技术价值不仅体现在代码实现,更在于架构选型、混合开发与跨端协作的工程决策能力。随着Apple Intelligence和AI辅助编程工具的普及,原生开发正在从单纯编码走向系统级智能应用的深度融合。本文以十年实战视角,梳理iOS开

weixin_33802505的博客 270

SwiftUI 控件

SwiftUI View控件 持续学习更新中… 1. Text 文字(相当于Swift 和 OC 中的 UILabel) Text("Text ") .bold() //加粗 .italic() //斜体 .kerning(10)//字间距 .underline() //下划线 .frame(width: 250, height: 35 alignment: .leading) // 文字尺寸、展示方式 .font(.system(size: 20)) /

优快云博客 3677

iOS健康数据整合开发实战:SwiftUI与HealthKit构建一体化应用

在移动应用开发领域,数据整合与本地化存储是提升用户体验的关键技术。其核心原理在于通过统一的框架管理多源数据,打破信息孤岛,实现高效的数据同步与可视化。这一技术价值在于能够构建更智能、更个性化的应用服务,尤其在健康管理、运动追踪等场景中至关重要。开发者可以利用SwiftUI构建声明式用户界面,结合Core Data实现本地数据持久化,并通过HealthKit安全地集成系统健康数据。例如,在构建一体化健康管理应用时,SwiftUI的响应式特性与HealthKit的数据读写能力相结合,能够实现卡路里、运动量等数据

weixin_30730053的博客 449
上一篇: JAVA的类转map的工具类,网络请求里面用的到
下一篇: csdn博客中动态动画的创建,mac版本的实现步骤
千雅爸爸
博客等级 码龄18年 292粉丝 639原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值