关于 ios-storyboard
ios-storyboard 是用于维护诊所项目中既有 iOS Storyboard 界面的技能,不适用于新 SwiftUI 功能开发。其分级规则涵盖 Interface Builder 中的布局、导航、适配性、无障碍和协作。
主要功能
- 01Storyboard 场景组织
- 02Auto Layout 约束指南
- 03Segue 与导航模式
- 04适配不同尺寸类别的布局
- 05无障碍与 VoiceOver 规则
- 06Storyboard 审查与调试
适用场景
- 01在 Interface Builder 中修改场景
- 02审查自适应布局与约束
- 03处理 Storyboard 差异和合并冲突
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ pproenca/ dot-skills --skill ios-storyboard安装后在 Claude Code 中输入/ios-storyboard确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
metadata.jsonassets/templates/_template.mdreferences/_sections.mdadapt-dynamic-type.mdadapt-readable-content-guide.mdadapt-safe-area-all-devices.mdadapt-size-classes.mdadapt-trait-variations.mdally-dynamic-labels.mdally-grouping.mdally-identifiers.mdally-labels.mdally-traits.mdarch-avoid-hardcoded-identifiers.mdarch-initial-view-controller.mdarch-modular-xibs.mdarch-one-scene-per-flow.mdarch-scene-naming.mdarch-split-storyboards.mdarch-storyboard-references.mddebug-ambiguous-layout.mddebug-constraint-identifier.mddebug-stale-outlets.mddebug-view-hierarchy.mdlayout-avoid-constant-offsets.mdlayout-avoid-fixed-dimensions.mdlayout-constraint-nearest-neighbor.mdlayout-constraint-priorities.mdlayout-content-hugging.mdlayout-inequality-constraints.md详细介绍
iOS Storyboard 最佳实践
针对诊所项目中仍在使用的、以 Storyboard 为主的代码提供旧版互操作指南。不适用于新的 SwiftUI 诊所功能开发。
全面介绍 Xcode Storyboard 和 Interface Builder 的 UI 设计与架构指南,重点讲解如何构建易于维护、适配性强且无障碍的 iOS 界面。包含 8 个类别中的 45 条规则,按影响程度排序,为自动重构和代码生成提供指导。
诊所架构约定(iOS 26 / Swift 6.2)
本技能中的所有指南均基于诊所模块化 MVVM-C 架构:
- 功能模块仅导入
Domain+DesignSystem(绝不导入Data,也不导入同级功能模块) - App target 是汇合点,负责管理
DependencyContainer、具体协调器和 Route Shell 连接 Domain保持纯 Swift,定义模型以及 repository、*Coordinating、ErrorRouting和AppError契约Data负责 SwiftData/网络/同步/重试/后台 I/O,并实现 Domain 协议- 读写流程默认采用先返回陈旧数据、再重新验证的读取方式,以及乐观排队写入
- ViewModel 直接调用 repository 协议(不设默认的 use-case/interactor 层)
适用场景
以下情况可参考这些指南:
- 在 Xcode Interface Builder 中创建或修改 Storyboard 场景
- 为适配性布局设置 Auto Layout 约束
- 使用 segue 和 storyboard 引用设计导航流程
- 为通用应用配置 size class 和 trait 变体
- 审查 storyboard XML 差异并解决合并冲突
按优先级划分的规则类别
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | Storyboard 架构 | 严重 | arch- |
| 2 | Auto Layout 约束 | 严重 | layout- |
| 3 | 导航与 Segue | 高 | nav- |
| 4 | 适配性布局与 Size Class | 高 | adapt- |
| 5 | 视图层级与 Stack View | 中高 | view- |
| 6 | 无障碍与 VoiceOver | 中 | ally- |
| 7 | 版本控制与协作 | 中 | vcs- |
| 8 | 调试与检查 | 中低 | debug- |
快速参考
1. Storyboard 架构(严重)
arch-split-storyboards- 将单体 Storyboard 拆分到各功能模块arch-storyboard-references- 使用 Storyboard 引用实现跨模块导航arch-one-scene-per-flow- 每个 Storyboard 限定为单个用户流程arch-initial-view-controller- 在每个 Storyboard 中显式设置初始视图控制器arch-avoid-hardcoded-identifiers- 避免硬编码 Storyboard 和 Cell 标识符arch-scene-naming- 在 Document Outline 中使用描述性场景标签arch-modular-xibs- 将可复用视图提取到独立的 XIB 文件中
2. 自动布局约束(关键)
layout-avoid-fixed-dimensions- 避免固定宽度和高度约束layout-leading-trailing- 使用 Leading 和 Trailing,而不是 Left 和 Rightlayout-safe-area- 将视图约束到安全区域参考线layout-content-hugging- 设置内容拥抱和压缩阻力优先级layout-constraint-nearest-neighbor- 将视图约束到最近的相邻视图layout-avoid-constant-offsets- 使用布局边距,而不是固定偏移量layout-inequality-constraints- 使用不等式约束设置灵活的最小值和最大值layout-constraint-priorities- 为可选约束分配不同的优先级
3. 导航与 Segue(高)
nav-prepare-for-segue- 通过 prepare(for:sender:) 传递数据,而不是直接访问属性nav-unwind-segues- 使用 Unwind Segue 向后导航nav-avoid-mixed-navigation- 避免混用 Segue 和编程式导航nav-adaptive-segues- 使用 Show 和 Show Detail,而不是 Push 和 Modalnav-perform-segue-validation- 使用 shouldPerformSegue 验证 Segue 条件nav-container-view-controllers- 使用容器视图嵌入子视图控制器
4. 自适应布局与尺寸类别(高)
adapt-size-classes- 使用 Vary for Traits 按尺寸类别配置约束adapt-trait-variations- 使用 Trait Variations 调整字体和间距adapt-safe-area-all-devices- 在所有设备尺寸类别上测试自适应布局adapt-readable-content-guide- 在大屏幕上使用可读内容参考线显示文本adapt-dynamic-type- 为所有文本标签支持动态字体
5. 视图层级与堆栈视图(中高)
view-prefer-stack-views- 对于线性布局,使用堆栈视图,而不是手动设置约束view-avoid-deep-nesting- 避免堆栈视图嵌套超过两层view-intrinsic-content-size- 使用标准 UIKit 控件的固有内容尺寸view-placeholder-intrinsic-size- 在 Storyboard 中为自定义视图使用占位符固有尺寸view-clip-to-bounds- 为带圆角的视图启用 Clip to Boundsview-content-mode- 在 Storyboard 中为 UIImageView 设置正确的内容模式
6. 无障碍与 VoiceOver(中)
ally-labels- 为所有交互元素设置无障碍标签ally-traits- 在 Interface Builder 中分配正确的无障碍特征ally-grouping- 对相关元素分组,以便通过 VoiceOver 导航ally-identifiers- 为 UI 测试设置无障碍标识符ally-dynamic-labels- 更新动态内容的无障碍标签
7. 版本控制与协作(中)
vcs-one-scene-per-developer- 为每位开发者分配 Storyboard 场景vcs-open-as-source- 提交前以源代码形式审查 Storyboard 差异vcs-lock-storyboard-files- 使用 Git 文件锁定来处理正在编辑的 Storyboardvcs-gitattributes-merge- 配置 .gitattributes,为 Storyboard 使用并集合并
8. 调试与检查(低至中)
debug-view-hierarchy- 使用 Debug View Hierarchy 检查布局问题debug-ambiguous-layout- 使用 hasAmbiguousLayout 在运行时检测约束问题debug-constraint-identifier- 为约束分配标识符,以便查看易读的日志debug-stale-outlets- 移除过期的 Outlet 连接,避免崩溃
使用方法
阅读各个参考文件,了解详细说明和代码示例:
参考文件
| 文件 | 描述 |
|---|---|
| references/_sections.md | 类别定义和排序 |
| assets/templates/_template.md | 新规则模板 |
| metadata.json | 版本和参考信息 |
评论
支持 Markdown