返回顶部
P

PagerKitPagerKit指南

Expert guidance on PagerKit, a SwiftUI library for advanced, customizable page-based navigation. Use when developers mention: (1) PagerKit, PKPagesView, PKPage, (2) custom page controls, indicators, or paging behavior, (3) cross-platform SwiftUI paging, (4) dynamic page generation, (5) integrating page views into custom layouts, (6) specific PagerKit modifiers or enums, (7) page view controller options, (8) event handling for page changes.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.1
安全检测
已通过
1,988
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

PagerKit

PagerKit 技能

概述

本技能提供关于 PagerKit 的专业指导,这是一个强大的 SwiftUI 库,用于创建高度可定制且跨平台的基于页面的导航。它涵盖了从基本用法和动态页面生成到页面指示器的高级定制、事件处理以及最佳实践的所有内容。使用本技能可帮助开发者在所有 Apple 平台的 SwiftUI 应用中有效实现灵活且视觉丰富的分页体验。

代理行为(遵循以下规则)

  1. 1. 明确分页需求: 在提供解决方案之前,始终确认用户在页面内容、指示器样式、导航流程和平台目标方面的具体需求。
  2. 优先使用地道的 SwiftUI: 优先使用 PagerKit 的 PKPageBuilder 和 ForEach 进行声明式页面构建,遵循 SwiftUI 的设计原则。
  3. 平台特定建议: 在讨论指示器图像、进度或 UIPageViewController 选项时,始终指定平台可用性和正确的类型(UIImage 与 Image、UIPageControlProgress)。
  4. 强调修饰符: 引导用户使用相关的 PKPagesView 或 PKPage 修饰符进行定制,使用完整的修饰符签名(例如 .pkPageNavigationOrientation(_:))。
  5. 上下文代码示例: 提供简洁的代码片段,说明在 PKPagesView 或 PKPage 上下文中的推荐用法。
  6. 突出跨平台性: 在可能的情况下,提醒用户 PagerKit 的跨平台一致性,以及如何使用 #if os(...) 指令处理平台特定差异。

项目设置

PagerKit 的行为受项目部署目标和 Swift 版本的影响。

  • - 部署目标: PagerKit 支持 iOS 14.0+、iPadOS 14.0+、macOS 14.0+、tvOS 14.0+、visionOS 1.0+ 和 watchOS 10.0+。某些功能(例如 UIPageControlProgress)仅在特定平台和操作系统版本上可用。
  • Swift 版本: 需要 Swift 5.9+。

如果这些未知,请要求开发者确认,尤其是在讨论平台特定功能时。

快速决策树

当开发者需要 PagerKit 指导时,遵循此决策树:

  1. 1. 正在设置新的分页器?
* 基本安装和概念 → references/PagerKit.md * 定义整体分页器结构 → references/PKPagesView.md * 创建单个页面内容 → references/PKPage.md
  1. 2. 从数据动态生成页面?
* 使用项目集合 → references/ForEach.md
  1. 3. 控制页面流程或结构?
* 添加条件页面(if/else) → references/PKPageBuilder.md * 设置水平或垂直导航 → references/PKPagesView.md(.pkPageNavigationOrientation)
  1. 4. 自定义页面指示器(圆点)?
* 更改颜色(活动/非活动) → references/PKPagesView.md(.pkPageControlIndicatorTintColor、.pkPageControlIndicatorCurrentIndicatorTintColor) * 更改背景样式(简约、突出、自动) → references/PKPageControlBackgroundStyle.md * 调整位置或间距 → references/PKPagesView.md(.pkPageControlIndicatorAlignment、.pkPageControlPadding) * 设置布局方向(例如垂直对齐) → references/PKPageControlDirection.md * 使用自定义图像(全局或每页) → references/PKPagesView.md、references/PKPage.md * 隐藏指示器(始终或单页时) → references/PKPagesView.md
  1. 5. 处理页面更改事件或状态?
* 绑定到当前页面索引 → references/PKPagesView.md(.pkCurrentPageIndex) * 响应手动页面更改 → references/PKPagesView.md(.pkOnManualPageChange) * 响应自动页面更改 → references/PKPagesView.md(.pkOnAutoPageChange) * 识别页面转换方向 → references/PKPageDirection.md * 转换开始/结束时的操作 → references/PKPagesView.md
  1. 6. 自定义单个页面行为?
* 设置自动转换持续时间 → references/PKPage.md(.pkPageDuration) * 向页面添加自定义页脚 → references/PKPage.md(.pkPageFooter)

分诊优先剧本

  • - 我的页面不显示或显示不正确。
* 验证 PKPagesView 包含有效的 PKPage 实例。参考 references/PKPagesView.md、references/PKPage.md。 * 如果使用动态内容,检查 ForEach 实现。参考 references/ForEach.md。
  • - 页面指示器位置或样式不正确。
* 检查 PKPagesView 上的 .pkPageControlIndicatorAlignment、.pkPageControlIndicatorBackgroundStyle、.pkPageControlIndicatorDirection 修饰符。参考 references/PKPagesView.md、references/PKPageControlBackgroundStyle.md、references/PKPageControlDirection.md。
  • - 我想更改活动圆点的颜色,但没有生效。
* 确保在 PKPagesView 上使用了 .pkPageControlIndicatorCurrentIndicatorTintColor(_:)。参考 references/PKPagesView.md。
  • - 页面没有自动转换。
* 检查是否在单个 PKPage 上应用了非 nil 持续时间的 .pkPageDuration(_:)。参考 references/PKPage.md。
  • - 我在 PKPagesView 内部的条件逻辑(if 语句)导致编译器错误。
* 查看 PKPageBuilder 概念,确保所有分支都返回有效的 PKPage 组件。参考 references/PKPageBuilder.md。
  • - 如何判断用户是向前还是向后滑动?
* 在 .pkOnManualPageChange 中使用 PKPageDirection 参数。参考 references/PKPagesView.md、references/PKPageDirection.md。

核心模式参考

基本分页器设置

swift
PKPagesView {
PKPage { Text(页面 A).font(.title) }
PKPage { Text(页面 B).font(.title) }
PKPage { Text(页面 C).font(.title) }
}
.pkCurrentPageIndex(index: $currentPage) // 绑定到 @State
.pkPageNavigationOrientation(.horizontal)

使用 ForEach 的动态页面

swift
struct Item: Identifiable {
let id = UUID()
let title: String
}

// ... 在 View 内部
let items = [Item(title: 项目 1), Item(title: 项目 2)]

PKPagesView {
ForEach(items) { item in
PKPage { Text(item.title) }
.pkPageFooter { Text(\(item.title) 的页脚) }
}
}

自定义页面指示器样式

swift
.pkPageControlIndicatorAlignment(spacing: 10, alignment: .bottomTrailing)
.pkPageControlIndicatorBackgroundStyle(.prominent)
.pkPageControlIndicatorDirection(.topToBottom) // 垂直圆点
.pkPageControlIndicatorTintColor(.gray)
.pkPageControlIndicatorCurrentIndicatorTintColor(.blue)
// 自定义图像
#if os(iOS)
.pkPageControlIndicatorPreferredCurrentPageIndicatorImage(image: UIImage(systemName: star.fill))
#else
.pkPageControlIndicatorPreferredCurrentPageIndicatorImage(image: Image(systemName: star.fill))
#endif

处理页面更改事件

swift
.pkOnManualPageChange { currentIndex, direction in
print(用户通过 \(direction) 方向导航到页面 \(currentIndex)。)
}
.pkOnAutoPageChange { previousIndex, currentIndex in
print(从 \(previousIndex) 自动更改为 \(currentIndex)。)
}
.pkOnTransitionEnd { previous, current in
print(转换结束。之前是 \(previous),现在是 \(current)。)
}

集成快速指南

PagerKit 通过 Swift Package Manager 集成。

  1. 1. 添加包依赖: 在 Xcode 中,转到 文件 > 添加包依赖 并输入 https://github.com/SzpakKamil/PagerKit.git。
  2. 导入: 在 Swift 文件中使用 import PagerKit。
  3. 部署目标: 确保您的项目目标为 iOS 14.0+、iPadOS 14.0+、macOS 14.0+、tvOS 14.0+、visionOS 1.0+ 或 watchOS 10.0+(Swift 5.9+)。

有关详细设置,请参阅 references/PagerKit.md。

参考文件

根据需要加载这些

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 pagerkit-1776389946 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 pagerkit-1776389946 技能

通过命令行安装

skillhub install pagerkit-1776389946

下载

⬇ 下载 PagerKit v1.0.1(免费)

文件大小: 15.08 KB | 发布时间: 2026-4-17 15:36

v1.0.1 最新 2026-4-17 15:36
**PagerKit 1.0.1 Changelog**

- Updated code examples to use explicit parameter labels in modifiers (e.g., `.pkCurrentPageIndex(index: $currentPage)`, `.pkPageControlIndicatorPreferredCurrentPageIndicatorImage(image:)`) for improved clarity and alignment with API changes.
- Refined quick reference and usage sections to match the latest PagerKit API signatures.
- Ensured all sample code and documentation reflect stricter Swift 5.9 syntax requirements.
- Corrected several modifier usages and descriptions for accuracy based on recent documentation updates.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部