1e41f4b71Sopenharmony_ci# Swiper 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 滑块视图容器,提供子组件滑动轮播显示的能力。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> - Swiper组件[通用属性clip](ts-universal-attributes-sharp-clipping.md)的默认值为true。 10e41f4b71Sopenharmony_ci> 11e41f4b71Sopenharmony_ci> - Swiper组件内包含了[PanGesture](ts-basic-gestures-pangesture.md)拖动手势事件,用于滑动轮播子组件。[disableSwipe](#disableswipe8)属性设为true会取消内部的PanGesture事件监听。 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## 子组件 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci可以包含子组件。 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci> **说明:** 18e41f4b71Sopenharmony_ci> 19e41f4b71Sopenharmony_ci> - 子组件类型:系统组件和自定义组件,支持渲染控制类型([if/else](../../../quick-start/arkts-rendering-control-ifelse.md)、[ForEach](../../../quick-start/arkts-rendering-control-foreach.md)、[LazyForEach](../../../quick-start/arkts-rendering-control-lazyforeach.md)和[Repeat](../../../quick-start/arkts-new-rendering-control-repeat.md))。不建议子组件中混用懒加载组件(包括LazyForEach、Repeat)和非懒加载组件,或者子组件中使用多个懒加载组件,否则可能导致懒加载组件预加载能力失效等问题。 20e41f4b71Sopenharmony_ci> 21e41f4b71Sopenharmony_ci> - Swiper子组件的visibility属性设置为None,Swiper的displayCount属性设置为'auto'时,对应子组件在视窗内不占位,但不影响导航点个数。 22e41f4b71Sopenharmony_ci> 23e41f4b71Sopenharmony_ci> - Swiper子组件的visibility属性设置为None,或者visibility属性设置为Hidden时,对应子组件不显示,但依然会在视窗内占位。 24e41f4b71Sopenharmony_ci> 25e41f4b71Sopenharmony_ci> - 当Swiper子组件个数小于等于Swiper组件内容区内显示的节点总个数(totalDisplayCount = DisplayCount + prevMargin? (1 : 0) + nextMargin? (1 : 0))时,一般按照非循环模式布局处理,此时,前后边距对应子组件不显示,但依然会在视窗内占位。Swiper组件按照totalDisplayCount个数判断测算规格。例外情况如下: 26e41f4b71Sopenharmony_ci> 27e41f4b71Sopenharmony_ci> - 当Swiper子组件个数等于Swiper组件内容区内显示的节点总个数且prevMargin和nextMargin都生效时,设置loop为true支持循环。 28e41f4b71Sopenharmony_ci> 29e41f4b71Sopenharmony_ci> - 当Swiper子组件个数等于Swiper组件DisplayCount数 + 1,且prevMargin和nextMargin至少一个生效时,设置loop为true会生成截图占位组件(如果使用图片异步加载等显示耗时较长的组件可能不能正确生成截图,不建议在该场景开启循环),支持循环。 30e41f4b71Sopenharmony_ci> 31e41f4b71Sopenharmony_ci> - 当Swiper子组件设置了offset属性时,会按照子组件的层级进行绘制,层级高的子组件会覆盖层级低的子组件。例如,Swiper包含3个子组件,其中第3个子组件设置了offset({ x : 100 }),那么在横向循环滑动中,第3个子组件会覆盖第1个子组件,此时可设置第1个子组件的zIndex属性值大于第3个子组件,使第1个子组件层级高于第3个子组件。 32e41f4b71Sopenharmony_ci> 33e41f4b71Sopenharmony_ci> - 不建议在执行翻页动画过程中增加或减少子组件,会导致未进行动画的子组件提前进入视窗,引起显示异常。 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci## 接口 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ciSwiper(controller?: SwiperController) 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**参数:** 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 48e41f4b71Sopenharmony_ci| ---------- | ------------------------------------- | ---- | -------------------- | 49e41f4b71Sopenharmony_ci| controller | [SwiperController](#swipercontroller) | 否 | 给组件绑定一个控制器,用来控制组件翻页。 | 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci## 属性 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci### index 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ciindex(value: number) 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci设置当前在容器中显示的子组件的索引值。设置小于0或大于等于子组件数量时,按照默认值0处理。 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci从API version 10开始,该属性支持[$$](../../../quick-start/arkts-two-way-sync.md)双向绑定变量。 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci**参数:** 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 73e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------ | 74e41f4b71Sopenharmony_ci| value | number | 是 | 当前在容器中显示的子组件的索引值。<br/>默认值:0 <br/>**说明:** <br/>设置的值小于0或大于最大页面索引时,取0。| 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci### autoPlay 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ciautoPlay(value: boolean) 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci设置子组件是否自动播放。 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ciloop为false时,自动轮播到最后一页时停止轮播。手势切换后不是最后一页时继续播放。当Swiper不可见时会停止轮播。 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**参数:** 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 93e41f4b71Sopenharmony_ci| ------ | ------- | ---- | -------------------------------------- | 94e41f4b71Sopenharmony_ci| value | boolean | 是 | 子组件是否自动播放。<br/>默认值:false | 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci### interval 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ciinterval(value: number) 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci设置使用自动播放时播放的时间间隔。 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci**参数:** 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 111e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------------------------------------------- | 112e41f4b71Sopenharmony_ci| value | number | 是 | 自动播放时播放的时间间隔。<br/>默认值:3000<br/>单位:毫秒 | 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci### indicator 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ciindicator(value: DotIndicator | DigitIndicator | boolean) 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci设置可选导航点指示器样式。 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**参数:** 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 129e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 130e41f4b71Sopenharmony_ci| value | [DotIndicator](#dotindicator10)<sup>10+</sup> \| [DigitIndicator](#digitindicator10)<sup>10+</sup> \| boolean | 是 | 可选导航点指示器样式。<br/> \- DotIndicator:圆点指示器样式。<br/> \- DigitIndicator:数字指示器样式。<br/> \- boolean:是否启用导航点指示器。设置为true启用,false不启用。<br/> 默认值:true<br/> 默认类型:DotIndicator | 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci### loop 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ciloop(value: boolean) 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci设置是否开启循环。设置为true时表示开启循环,在LazyForEach懒循环加载模式下,加载的组件数量建议大于5个。 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci**参数:** 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 147e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- | 148e41f4b71Sopenharmony_ci| value | boolean | 是 | 是否开启循环。<br/>默认值:true | 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci### duration 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ciduration(value: number) 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci设置子组件切换的动画时长。 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ciduration需要和[curve](#curve8)一起使用。 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_cicurve默认曲线为[interpolatingSpring](../js-apis-curve.md#curvesinterpolatingspring10),此时动画时长只受曲线自身参数影响,不再受duration的控制。不受duration控制的曲线可以查阅[插值计算](../js-apis-curve.md)模块,比如,[springMotion](../js-apis-curve.md#curvesspringmotion9) 159e41f4b71Sopenharmony_ci、[responsiveSpringMotion](../js-apis-curve.md#curvesresponsivespringmotion9)和interpolatingSpring类型的曲线不受duration控制。如果希望动画时长受到duration控制,需要给curve设置其他曲线。 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci**参数:** 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 168e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------------------------------------- | 169e41f4b71Sopenharmony_ci| value | number | 是 | 子组件切换的动画时长。<br/>默认值:400<br/>单位:毫秒 | 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci### vertical 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_civertical(value: boolean) 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci设置是否为纵向滑动。 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci**参数:** 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 186e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------------- | 187e41f4b71Sopenharmony_ci| value | boolean | 是 | 是否为纵向滑动。true为纵向滑动,false为横向滑动。<br/>默认值:false | 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci### itemSpace 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ciitemSpace(value: number | string) 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci设置子组件与子组件之间间隙。不支持设置百分比。 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci类型为number时,默认单位vp。类型为string时,需要显式指定像素单位,如'10px';未指定像素单位时,如'10',单位为vp。 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci**参数:** 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 206e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | -------------------------------------- | 207e41f4b71Sopenharmony_ci| value | number \| string | 是 | 子组件与子组件之间间隙。<br/>默认值:0 | 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci### displayMode 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_cidisplayMode(value: SwiperDisplayMode) 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci设置主轴方向上元素排列的模式,优先以displayCount设置的个数显示,displayCount未设置时本属性生效。 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci**参数:** 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 224e41f4b71Sopenharmony_ci| ------ | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 225e41f4b71Sopenharmony_ci| value | [SwiperDisplayMode](#swiperdisplaymode枚举说明) | 是 | 主轴方向上元素排列的模式。<br/>默认值:SwiperDisplayMode.STRETCH | 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci### cachedCount<sup>8+</sup> 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_cicachedCount(value: number) 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci设置预加载子组件个数,以当前页面为基准,加载当前显示页面的前后个数。例如cachedCount=1时,会将当前显示的页面的前面一页和后面一页的子组件都预加载。如果设置为按组翻页,即displayCount的swipeByGroup参数设为true,预加载时会以组为基本单位。例如cachedCount=1,swipeByGroup=true时,会将当前组的前面一组和后面一组的子组件都预加载。 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**参数:** 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 242e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------- | 243e41f4b71Sopenharmony_ci| value | number | 是 | 预加载子组件个数。<br/>默认值:1 | 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci### disableSwipe<sup>8+</sup> 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_cidisableSwipe(value: boolean) 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci设置禁用组件滑动切换功能。 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci**参数:** 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 260e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------------------- | 261e41f4b71Sopenharmony_ci| value | boolean | 是 | 禁用组件滑动切换功能。设置为true禁用,false不禁用。<br/>默认值:false | 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci### curve<sup>8+</sup> 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_cicurve(value: Curve | string | ICurve) 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci设置Swiper的动画曲线,默认为弹簧插值曲线,常用曲线参考[Curve枚举说明](ts-appendix-enums.md#curve),也可以通过[插值计算](../js-apis-curve.md)模块提供的接口创建自定义的插值曲线对象。 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci**参数:** 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 278e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------- | 279e41f4b71Sopenharmony_ci| value | [Curve](ts-appendix-enums.md#curve) \| string \| [ICurve](../js-apis-curve.md#icurve9)<sup>10+</sup> | 是 | Swiper的动画曲线。<br/>默认值:interpolatingSpring(-1, 1, 328, 34) | 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci### indicatorStyle<sup>(deprecated)</sup> 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ciindicatorStyle(value?: IndicatorStyle) 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci设置导航点样式。 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci从API version 8开始支持,从API version 10开始不再维护,建议使用[indicator](#indicator10)代替。 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci**参数:** 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 294e41f4b71Sopenharmony_ci| ------ | --------------------------------------------------- | ---- | ------------ | 295e41f4b71Sopenharmony_ci| value | [IndicatorStyle](#indicatorstyledeprecated对象说明) | 否 | 导航点样式。 | 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci### displayCount<sup>8+</sup> 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_cidisplayCount(value: number | string | SwiperAutoFill, swipeByGroup?: boolean) 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci设置Swiper视窗内元素显示个数。 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci字符串类型仅支持设置为'auto'。 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci使用number类型且设置小于等于0时,按默认值1显示。 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci使用number类型时,子组件按照主轴均分Swiper宽度(减去displayCount-1个itemSpace)的方式进行主轴拉伸(收缩)布局。 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci使用SwiperAutoFill类型时,通过设置一个子组件最小宽度值minSize,会根据Swiper当前宽度和minSize值自动计算并更改一页内元素显示个数。当minSize为空或者小于等于0时,Swiper显示1列。 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci当按组进行翻页时,如果最后一组的子元素数量小于displayCount时,会使用占位子元素补齐。占位子元素只是用于布局占位,不显示任何内容。在占位子元素的位置会直接显示Swiper自身的背景样式。 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci在按组翻页时,判断翻页的拖拽距离阈值条件,会更新为Swiper自身宽度的一半。(按子元素翻页时,该阈值为子元素自身宽度的一半)。 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci**参数:** 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 324e41f4b71Sopenharmony_ci| -------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 325e41f4b71Sopenharmony_ci| value | number \| string \| [SwiperAutoFill](#swiperautofill10对象说明)<sup>10+</sup> | 是 | 视窗内显示的子元素个数。<br/> 默认值:1 | 326e41f4b71Sopenharmony_ci| swipeByGroup<sup>11+</sup> | boolean | 否 | 是否按组进行翻页。如果设为true,在翻页时会按组进行翻页,每组内子元素的数量为displayCount value的值;如果为false,则为默认翻页行为,即按照子元素进行翻页。<br/> 默认值:false | 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci### effectMode<sup>8+</sup> 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_cieffectMode(value: EdgeEffect) 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci设置边缘滑动效果,loop = false时生效。 目前支持的滑动效果参见EdgeEffect的枚举说明。控制器接口调用时不生效回弹。 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci**参数:** 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 343e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | -------------------------------------------- | 344e41f4b71Sopenharmony_ci| value | [EdgeEffect](ts-appendix-enums.md#edgeeffect) | 是 | 边缘滑动效果。<br/>默认值:EdgeEffect.Spring | 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ci### displayArrow<sup>10+</sup> 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_cidisplayArrow(value: ArrowStyle | boolean, isHoverShow?: boolean) 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci设置导航点箭头样式。 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci**参数:** 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 359e41f4b71Sopenharmony_ci| -------------------------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 360e41f4b71Sopenharmony_ci| value | [ArrowStyle](#arrowstyle10对象说明) \| boolean | 是 | 支持设置箭头和底板样式,异常场景使用ArrowStyle对象中的默认值。设置为false不显示箭头和底板,true显示默认的箭头和底板样式。<br/>默认值:false | 361e41f4b71Sopenharmony_ci| isHoverShow | boolean | 否 | 设置鼠标悬停时是否显示箭头。<br/>默认值:false<br/>**说明:**<br/>isHoverShow为false时,常驻显示箭头,支持点击翻页。<br/>isHoverShow为true时,只有在鼠标悬停时才会显示箭头,并支持点击翻页。 | 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci> **说明:** 364e41f4b71Sopenharmony_ci> 365e41f4b71Sopenharmony_ci> Swiper视窗内显示所有子节点时,只显示一屏,无法翻页,左右翻页箭头均不显示。 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci### nextMargin<sup>10+</sup> 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_cinextMargin(value: Length, ignoreBlank?:boolean) 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci设置后边距,用于露出后一项的一小部分。仅当Swiper子组件的布局方式为拉伸时生效,主要包括两种场景:1、displayMode属性设置为SwiperDisplayMode.STRETCH;2、displayCount属性设置为number类型。 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci当主轴方向为横向布局时,nextMargin/prevMargin中任意一个大于子组件测算的宽度,nextMargin和prevMargin均不显示。 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci当主轴方向为纵向布局时,nextMargin/prevMargin中任意一个大于子组件测算的高度,nextMargin和prevMargin均不显示。 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci**参数:** 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 384e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ---------------------- | 385e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 后边距。<br/>默认值:0 | 386e41f4b71Sopenharmony_ci| ignoreBlank<sup>12+</sup> | boolean | 否 | 非loop场景下尾页不显示nextMargin。在非loop场景下,设置为true时,尾页不显示空白的nextMargin,尾页的右边缘与Swiper视窗右边缘对齐;设置false时,尾页显示空白nextMargin,尾页的右边缘与Swiper视窗右边缘的距离为nextMargin。<br/>默认值:false <br/>**说明:**<br/>尾页场景下,prevMargin和nextMargin的值相加作为左边边距显示前一个页面。 | 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci### prevMargin<sup>10+</sup> 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ciprevMargin(value: Length, ignoreBlank?:boolean) 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci设置前边距,用于露出前一项的一小部分。仅当Swiper子组件的布局方式为拉伸时生效,主要包括两种场景:1、displayMode属性设置为SwiperDisplayMode.STRETCH;2、displayCount属性设置为number类型。 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_ci当主轴方向为横向布局时,nextMargin/prevMargin中任意一个大于子组件测算的宽度,nextMargin和prevMargin均不显示。 395e41f4b71Sopenharmony_ci 396e41f4b71Sopenharmony_ci当主轴方向为纵向布局时,nextMargin/prevMargin中任意一个大于子组件测算的高度,nextMargin和prevMargin均不显示。 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci**参数:** 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 405e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ---------------------- | 406e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 前边距。<br/>默认值:0 | 407e41f4b71Sopenharmony_ci| ignoreBlank<sup>12+</sup> | boolean | 否 | 非loop场景下首页不显示prevMargin。在非loop场景下,设置为true时,首页不显示空白的prevMargin,首页的左边缘与Swiper视窗左边缘对齐;设置false时,首页显示空白prevMargin,首页的左边缘与Swiper视窗左边缘的距离为prevMargin。<br/>默认值:false <br/>**说明:**<br/>首页场景下,prevMargin和nextMargin的值相加作为右边边距显示后一个页面。| 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci### nestedScroll<sup>11+</sup> 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_cinestedScroll(value: SwiperNestedScrollMode) 412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci设置Swiper组件和父组件的嵌套滚动模式。loop为true时Swiper组件没有边缘,不会触发父组件嵌套滚动。 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci**参数:** 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 422e41f4b71Sopenharmony_ci| ------ | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 423e41f4b71Sopenharmony_ci| value | [SwiperNestedScrollMode](#swipernestedscrollmode11枚举说明) | 是 | Swiper组件和父组件的嵌套滚动模式。<br/>默认值:SwiperNestedScrollMode.SELF_ONLY | 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ci> **说明:** 426e41f4b71Sopenharmony_ci> 427e41f4b71Sopenharmony_ci> 由于Swiper的抛滑动画逻辑和其它滚动类组件不同(Swiper一次只能滑动一页,抛滑时做翻页动画),当Swiper内嵌套其它滚动组件时,如果Swiper的翻页动画已经启动,将无法接受子节点上传的滚动偏移量。这时Swiper的翻页动画和子节点的边缘效果动画会同时执行。 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci### indicatorInteractive<sup>12+</sup> 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_ciindicatorInteractive(value: boolean) 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci设置禁用组件导航点交互功能。设置为true时表示导航点可交互。 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci**参数:** 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 442e41f4b71Sopenharmony_ci| ------ | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 443e41f4b71Sopenharmony_ci| value | boolean | 是 | 导航点是否可交互。<br/>默认值:true | 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci## IndicatorStyle<sup>(deprecated)</sup>对象说明 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci从API version 8开始支持,从API version 10开始不再维护,建议使用[indicator](#indicator10)代替。 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 452e41f4b71Sopenharmony_ci| ------------- | ------------------------------------------ | ---- | ---------------------------------------------------- | 453e41f4b71Sopenharmony_ci| left | [Length](ts-types.md#length) | 否 | 设置导航点左侧相对于Swiper的位置。<br/>未设置left和right时,进行自适应大小布局,按照指示器本身大小和Swiper的大小在主轴方向上进行居中对齐<br/>设置为0时:按照0位置布局计算<br/>优先级:高于right属性<br/>取值范围:[0,Swiper宽度-导航点区域宽度],超出该范围时,取最近的的边界值。 | 454e41f4b71Sopenharmony_ci| top | [Length](ts-types.md#length) | 否 | 设置导航点顶部相对于Swiper的位置。<br/>未设置top和bottom时,进行自适应大小布局,按照指示器本身大小和Swiper的大小,在交叉轴方向上,位于底部,效果与设置bottom=0一致<br/>设置为0时:按照0位置布局计算<br/>优先级:高于bottom属性<br/>取值范围:[0,Swiper高度-导航点区域高度],超出该范围时,取最近的边界值。 | 455e41f4b71Sopenharmony_ci| right | [Length](ts-types.md#length) | 否 | 设置导航点右侧相对于Swiper的位置。<br/>未设置left和right时,进行自适应大小布局,按照指示器本身大小和Swiper的大小在主轴方向上进行居中对齐<br/>设置为0时:按照0位置布局计算<br/>优先级:低于left属性<br/>取值范围:[0,Swiper宽度-导航点区域宽度],超出该范围时,取最近的边界值。 | 456e41f4b71Sopenharmony_ci| bottom | [Length](ts-types.md#length) | 否 | 设置导航点底部相对于Swiper的位置。<br/>未设置top和bottom时,进行自适应大小布局,按照指示器本身大小和Swiper的大小,在交叉轴方向上,位于底部,效果与设置bottom=0一致<br/>设置为0时:按照0位置布局计算<br/>优先级:低于top属性<br/>取值范围:[0,Swiper高度-导航点区域高度],超出该范围时,取最近的边界值。 | 457e41f4b71Sopenharmony_ci| size | [Length](ts-types.md#length) | 否 | 设置导航点的直径,不支持设置百分比。<br/>默认值:6vp | 458e41f4b71Sopenharmony_ci| mask | boolean | 否 | 设置是否显示导航点蒙层样式。 | 459e41f4b71Sopenharmony_ci| color | [ResourceColor](ts-types.md#resourcecolor) | 否 | 设置导航点的颜色。 | 460e41f4b71Sopenharmony_ci| selectedColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | 设置选中的导航点的颜色。 | 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ci## SwiperDisplayMode枚举说明 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ciSwiper在主轴上的尺寸大小模式枚举。 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci| 名称 | 说明 | 469e41f4b71Sopenharmony_ci| ---------------------------------- | ------------------------------------------------------------ | 470e41f4b71Sopenharmony_ci| Stretch<sup>(deprecated)</sup> | Swiper滑动一页的宽度为Swiper组件自身的宽度。<br>从API version 10开始不再维护,建议使用STRETCH代替。<br/>**卡片能力:** 从API version 7开始,该接口支持在ArkTS卡片中使用。 | 471e41f4b71Sopenharmony_ci| AutoLinear<sup>(deprecated)</sup> | Swiper滑动一页的宽度为子组件宽度中的最大值。<br>从API version 10开始不再维护,建议使用[Scroller.scrollTo](ts-container-scroll.md#scrollto)代替。<br/>**卡片能力:** 从API version 7开始,该接口支持在ArkTS卡片中使用。 | 472e41f4b71Sopenharmony_ci| STRETCH<sup>10+</sup> | Swiper滑动一页的宽度为Swiper组件自身的宽度。<br/>**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 473e41f4b71Sopenharmony_ci| AUTO_LINEAR<sup>(deprecated)</sup> | Swiper滑动一页的宽度为视窗内最左侧子组件的宽度。<br/>从API version 10开始支持,从API version 12开始不再维护,建议使用[Scroller.scrollTo](ts-container-scroll.md#scrollto)代替。<br/>**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci## SwiperNestedScrollMode<sup>11+</sup>枚举说明 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ciSwiper组件和父组件的嵌套滚动模式枚举。 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 484e41f4b71Sopenharmony_ci| ------------ | -- | ---------------------------------------- | 485e41f4b71Sopenharmony_ci| SELF_ONLY | 0 | Swiper只自身滚动,不与父组件联动。 | 486e41f4b71Sopenharmony_ci| SELF_FIRST | 1 | Swiper自身先滚动,自身滚动到边缘以后父组件滚动。父组件滚动到边缘以后,如果父组件有边缘效果,则父组件触发边缘效果,否则Swiper触发边缘效果。 | 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci## SwiperController 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ciSwiper容器组件的控制器,可以将此对象绑定至Swiper组件,可以通过它控制翻页。 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 495e41f4b71Sopenharmony_ci 496e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ci### 导入对象 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ci```ts 501e41f4b71Sopenharmony_cilet controller: SwiperController = new SwiperController() 502e41f4b71Sopenharmony_ci``` 503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_ci### constructor 505e41f4b71Sopenharmony_ci 506e41f4b71Sopenharmony_ciconstructor() 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ciSwiperController的构造函数。 509e41f4b71Sopenharmony_ci 510e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 511e41f4b71Sopenharmony_ci 512e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci### showNext 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_cishowNext() 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci翻至下一页。翻页带动效切换过程,时长通过duration指定。 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 527e41f4b71Sopenharmony_ci 528e41f4b71Sopenharmony_ci### showPrevious 529e41f4b71Sopenharmony_ci 530e41f4b71Sopenharmony_cishowPrevious() 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci翻至上一页。翻页带动效切换过程,时长通过duration指定。 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ci### changeIndex<sup>12+</sup> 541e41f4b71Sopenharmony_ci 542e41f4b71Sopenharmony_cichangeIndex(index: number, useAnimation?: boolean) 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ci翻至指定页面。 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_ci**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 551e41f4b71Sopenharmony_ci 552e41f4b71Sopenharmony_ci**参数:** 553e41f4b71Sopenharmony_ci 554e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 555e41f4b71Sopenharmony_ci| -------- | ---------- | ---- | -------- | 556e41f4b71Sopenharmony_ci| index| number | 是 | 指定页面在Swiper中的索引值。<br/>**说明:** <br/>设置的值小于0或大于最大页面索引时,取0。 | 557e41f4b71Sopenharmony_ci| useAnimation| boolean | 否 | 设置翻至指定页面时是否有动效,true表示有动效,false表示没有动效。<br/>默认值:false。 | 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci### finishAnimation 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_cifinishAnimation(callback?: () => void) 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci停止播放动画。 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci**参数:** 572e41f4b71Sopenharmony_ci 573e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 574e41f4b71Sopenharmony_ci| -------- | ---------- | ---- | -------- | 575e41f4b71Sopenharmony_ci| callback | () => void | 否 | 动画结束的回调。 | 576e41f4b71Sopenharmony_ci 577e41f4b71Sopenharmony_ci## Indicator<sup>10+</sup> 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci设置导航点距离Swiper组件距离。由于导航点有默认交互区域,交互区域高度为32vp, 所以无法让显示部分完全贴底。 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 584e41f4b71Sopenharmony_ci 585e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ci### left 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_cileft(value: Length) 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci导航点左侧相对于Swiper的位置。 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ci**参数:** 600e41f4b71Sopenharmony_ci 601e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 602e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------------------------------------------ | 603e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 设置导航点左侧相对于Swiper的位置。<br/>未设置left和right时,进行自适应大小布局,按照指示器本身大小和Swiper的大小在主轴方向上进行居中对齐。<br/>设置为0时:按照0位置布局计算。<br/>优先级:高于right属性。<br/>取值范围:[0,Swiper宽度-导航点区域宽度],超出该范围时,取最近的的边界值。 | 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_ci### top 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_citop(value: Length) 608e41f4b71Sopenharmony_ci 609e41f4b71Sopenharmony_ci导航点顶部相对于Swiper的位置。 610e41f4b71Sopenharmony_ci 611e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 612e41f4b71Sopenharmony_ci 613e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 614e41f4b71Sopenharmony_ci 615e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci**参数:** 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 620e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------------------------------------------ | 621e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 设置导航点顶部相对于Swiper的位置。<br/>未设置top和bottom时,进行自适应大小布局,按照指示器本身大小和Swiper的大小,在交叉轴方向上,位于底部,效果与设置bottom=0一致。<br/>设置为0时:按照0位置布局计算。<br/>优先级:高于bottom属性。<br/>取值范围:[0,Swiper高度-导航点区域高度],超出该范围时,取最近的边界值。 | 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci### right 624e41f4b71Sopenharmony_ci 625e41f4b71Sopenharmony_ciright(value: Length) 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_ci导航点右侧相对于Swiper的位置。 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 634e41f4b71Sopenharmony_ci 635e41f4b71Sopenharmony_ci**参数:** 636e41f4b71Sopenharmony_ci 637e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 638e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------------------------------------------ | 639e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 设置导航点右侧相对于Swiper的位置。<br/>未设置left和right时,进行自适应大小布局,按照指示器本身大小和Swiper的大小在主轴方向上进行居中对齐。<br/>设置为0时:按照0位置布局计算。<br/>优先级:低于left属性。<br/>取值范围:[0,Swiper宽度-导航点区域宽度],超出该范围 时,取最近的边界值。 | 640e41f4b71Sopenharmony_ci 641e41f4b71Sopenharmony_ci### bottom 642e41f4b71Sopenharmony_ci 643e41f4b71Sopenharmony_cibottom(value: Length) 644e41f4b71Sopenharmony_ci 645e41f4b71Sopenharmony_ci导航点底部相对于Swiper的位置。 646e41f4b71Sopenharmony_ci 647e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 648e41f4b71Sopenharmony_ci 649e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 650e41f4b71Sopenharmony_ci 651e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_ci**参数:** 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 656e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------------------------------------------ | 657e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 设置导航点底部相对于Swiper的位置。<br/>未设置top和bottom时,进行自适应大小布局,按照指示器本身大小和Swiper的大小,在交叉轴方向上,位于底部,效果与设置bottom=0一致。<br/>设置为0时:按照0位置布局计算。<br/>优先级:低于top属性。<br/>取值范围:[0,Swiper高度-导航点区域高度],超出该范围时,取最近的边界值。 | 658e41f4b71Sopenharmony_ci 659e41f4b71Sopenharmony_ci### start<sup>12+</sup> 660e41f4b71Sopenharmony_ci 661e41f4b71Sopenharmony_cistart(value: LengthMetrics) 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ci在RTL模式下为导航点距离Swiper组件右边的距离,在LTR模式下为导航点距离Swiper组件左边的距离。 664e41f4b71Sopenharmony_ci 665e41f4b71Sopenharmony_ci**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 666e41f4b71Sopenharmony_ci 667e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci**参数:** 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 674e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 675e41f4b71Sopenharmony_ci| value | [LengthMetrics](../js-apis-arkui-graphics.md#lengthmetrics12) | 是 | 设置在RTL模式下为导航点距离Swiper组件右边的距离,在LTR模式下为导航点距离Swiper组件左边的距离<br/>默认值:0<br/>单位:vp | 676e41f4b71Sopenharmony_ci 677e41f4b71Sopenharmony_ci### end<sup>12+</sup> 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ciend(value: LengthMetrics) 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_ci在RTL模式下为导航点距离Swiper组件左边的距离,在LTR模式下为导航点距离Swiper组件右边的距离。 682e41f4b71Sopenharmony_ci 683e41f4b71Sopenharmony_ci**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 684e41f4b71Sopenharmony_ci 685e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 688e41f4b71Sopenharmony_ci 689e41f4b71Sopenharmony_ci**参数:** 690e41f4b71Sopenharmony_ci 691e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 692e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ---------------------------------------- | 693e41f4b71Sopenharmony_ci| value | [LengthMetrics](../js-apis-arkui-graphics.md#lengthmetrics12) | 是 | 设置在RTL模式下为导航点距离Swiper组件左边的距离,在LTR模式下为导航点距离Swiper组件右边的距离。<br/>默认值:0<br/>单位:vp <br/>**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci### dot 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_cistatic dot(): DotIndicator 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_ci返回一个DotIndicator对象。 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ci### digit 708e41f4b71Sopenharmony_ci 709e41f4b71Sopenharmony_cistatic digit(): DigitIndicator 710e41f4b71Sopenharmony_ci 711e41f4b71Sopenharmony_ci返回一个DigitIndicator对象。 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 716e41f4b71Sopenharmony_ci 717e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ci## DotIndicator<sup>10+</sup> 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_ci圆点指示器属性及功能继承自[Indicator](#indicator10)。 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ci### itemWidth 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_ciitemWidth(value: Length) 730e41f4b71Sopenharmony_ci 731e41f4b71Sopenharmony_ciSwiper组件圆点导航指示器的宽,不支持设置百分比。 732e41f4b71Sopenharmony_ci 733e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 734e41f4b71Sopenharmony_ci 735e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 736e41f4b71Sopenharmony_ci 737e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 738e41f4b71Sopenharmony_ci 739e41f4b71Sopenharmony_ci**参数:** 740e41f4b71Sopenharmony_ci 741e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 742e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------------------------------------------ | 743e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 设置Swiper组件圆点导航指示器的宽,不支持设置百分比。<br/>默认值:6<br/>单位:vp | 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci### itemHeight 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ciitemHeight(value: Length) 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ciSwiper组件圆点导航指示器的高,不支持设置百分比。 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci**参数:** 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 760e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------------------------------------------ | 761e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 设置Swiper组件圆点导航指示器的高,不支持设置百分比。<br/>默认值:6<br/>单位:vp | 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci### selectedItemWidth 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ciselectedItemWidth(value: Length) 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ci选中Swiper组件圆点导航指示器的宽,不支持设置百分比。 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 774e41f4b71Sopenharmony_ci 775e41f4b71Sopenharmony_ci**参数:** 776e41f4b71Sopenharmony_ci 777e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 778e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------------------------------------------ | 779e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 设置选中Swiper组件圆点导航指示器的宽,不支持设置百分比。<br/>默认值:12<br/>单位:vp | 780e41f4b71Sopenharmony_ci 781e41f4b71Sopenharmony_ci### selectedItemHeight 782e41f4b71Sopenharmony_ci 783e41f4b71Sopenharmony_ciselectedItemHeight(value: Length) 784e41f4b71Sopenharmony_ci 785e41f4b71Sopenharmony_ci选中Swiper组件圆点导航指示器的高,不支持设置百分比。 786e41f4b71Sopenharmony_ci 787e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 788e41f4b71Sopenharmony_ci 789e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 790e41f4b71Sopenharmony_ci 791e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 792e41f4b71Sopenharmony_ci 793e41f4b71Sopenharmony_ci**参数:** 794e41f4b71Sopenharmony_ci 795e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 796e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------------------------------------------ | 797e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 设置选中Swiper组件圆点导航指示器的高,不支持设置百分比。<br/>默认值:6<br/>单位:vp | 798e41f4b71Sopenharmony_ci 799e41f4b71Sopenharmony_ci### mask 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_cimask(value: boolean) 802e41f4b71Sopenharmony_ci 803e41f4b71Sopenharmony_ci是否显示Swiper组件圆点导航指示器的蒙版样式。 804e41f4b71Sopenharmony_ci 805e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 806e41f4b71Sopenharmony_ci 807e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 808e41f4b71Sopenharmony_ci 809e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 810e41f4b71Sopenharmony_ci 811e41f4b71Sopenharmony_ci**参数:** 812e41f4b71Sopenharmony_ci 813e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 814e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ | 815e41f4b71Sopenharmony_ci| value | boolean | 是 | 设置是否显示Swiper组件圆点导航指示器的蒙版样式。<br/>默认值:false | 816e41f4b71Sopenharmony_ci 817e41f4b71Sopenharmony_ci### color 818e41f4b71Sopenharmony_ci 819e41f4b71Sopenharmony_cicolor(value: ResourceColor) 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ciSwiper组件圆点导航指示器的颜色。 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 828e41f4b71Sopenharmony_ci 829e41f4b71Sopenharmony_ci**参数:** 830e41f4b71Sopenharmony_ci 831e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 832e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------------------------------------------------ | 833e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | 是 | 设置Swiper组件圆点导航指示器的颜色。<br/>默认值:'\#182431'(10%透明度) | 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_ci### selectedColor 836e41f4b71Sopenharmony_ci 837e41f4b71Sopenharmony_ciselectedColor(value: ResourceColor) 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_ci选中Swiper组件圆点导航指示器的颜色。 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 846e41f4b71Sopenharmony_ci 847e41f4b71Sopenharmony_ci**参数:** 848e41f4b71Sopenharmony_ci 849e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 850e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------------------------------------------------ | 851e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | 是 | 设置选中Swiper组件圆点导航指示器的颜色。<br/>默认值:'\#007DFF' | 852e41f4b71Sopenharmony_ci 853e41f4b71Sopenharmony_ci### maxDisplayCount<sup>12+</sup> 854e41f4b71Sopenharmony_ci 855e41f4b71Sopenharmony_cimaxDisplayCount(maxDisplayCount: number) 856e41f4b71Sopenharmony_ci 857e41f4b71Sopenharmony_ci圆点导航点指示器样式下,导航点显示个数最大值。 858e41f4b71Sopenharmony_ci 859e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 862e41f4b71Sopenharmony_ci 863e41f4b71Sopenharmony_ci**参数:** 864e41f4b71Sopenharmony_ci 865e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 866e41f4b71Sopenharmony_ci| --------------- | ------ | ---- | ------------------------------------------------------------ | 867e41f4b71Sopenharmony_ci| maxDisplayCount | number | 是 | 设置圆点导航点指示器样式下,导航点显示个数最大值,当实际导航点个数大于最大导航点个数时,会生效超长效果样式,样式如示例5所示。<br/>默认值:这个属性没有默认值,如果设置异常值那等同于没有超长显示效果。<br/>取值范围:6-9<br/>**说明:** <br/>1、超长显示场景,目前暂时不支持交互功能(包括:手指点击拖拽、鼠标操作等)。<br/>2、在超长显示场景下,中间页面对应的选中导航点的位置,并不是完全固定的,取决于之前的翻页操作序列。 | 868e41f4b71Sopenharmony_ci 869e41f4b71Sopenharmony_ci### constructor 870e41f4b71Sopenharmony_ci 871e41f4b71Sopenharmony_ciconstructor() 872e41f4b71Sopenharmony_ci 873e41f4b71Sopenharmony_ciDotIndicator的构造函数。 874e41f4b71Sopenharmony_ci 875e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 878e41f4b71Sopenharmony_ci 879e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_ci>**说明:** 882e41f4b71Sopenharmony_ci> 883e41f4b71Sopenharmony_ci>按压导航点时,导航点会放大至1.33倍显示,因此非按压态时导航点的可见范围边界至实际范围边界存在一定距离,该距离会随着itemWidth、itemHeight、selectedItemWidth、selectedItemHeight等参数变大而变大。 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci## DigitIndicator<sup>10+</sup> 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ci数字指示器属性及功能继承自[Indicator](#indicator10)。 888e41f4b71Sopenharmony_ci 889e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci>**说明:** 896e41f4b71Sopenharmony_ci> 897e41f4b71Sopenharmony_ci>按组翻页时,数字导航点显示的子节点数量,不包括占位节点。 898e41f4b71Sopenharmony_ci 899e41f4b71Sopenharmony_ci### fontColor 900e41f4b71Sopenharmony_ci 901e41f4b71Sopenharmony_cifontColor(value: ResourceColor) 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ciSwiper组件数字导航点的字体颜色。 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 906e41f4b71Sopenharmony_ci 907e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 908e41f4b71Sopenharmony_ci 909e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 910e41f4b71Sopenharmony_ci 911e41f4b71Sopenharmony_ci**参数:** 912e41f4b71Sopenharmony_ci 913e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 914e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------------------------------------------------ | 915e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | 是 | 设置Swiper组件数字导航点的字体颜色。<br/>默认值:'\#ff182431' | 916e41f4b71Sopenharmony_ci 917e41f4b71Sopenharmony_ci### selectedFontColor 918e41f4b71Sopenharmony_ci 919e41f4b71Sopenharmony_ciselectedFontColor(value: ResourceColor) 920e41f4b71Sopenharmony_ci 921e41f4b71Sopenharmony_ci选中Swiper组件数字导航点的字体颜色。 922e41f4b71Sopenharmony_ci 923e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 924e41f4b71Sopenharmony_ci 925e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 926e41f4b71Sopenharmony_ci 927e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 928e41f4b71Sopenharmony_ci 929e41f4b71Sopenharmony_ci**参数:** 930e41f4b71Sopenharmony_ci 931e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 932e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------------------------------------------------ | 933e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | 是 | 设置选中Swiper组件数字导航点的字体颜色。<br/>默认值:'\#ff182431' | 934e41f4b71Sopenharmony_ci 935e41f4b71Sopenharmony_ci### digitFont 936e41f4b71Sopenharmony_ci 937e41f4b71Sopenharmony_cidigitFont(value: Font) 938e41f4b71Sopenharmony_ci 939e41f4b71Sopenharmony_ciSwiper组件数字导航点的字体样式。 940e41f4b71Sopenharmony_ci 941e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 942e41f4b71Sopenharmony_ci 943e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 944e41f4b71Sopenharmony_ci 945e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 946e41f4b71Sopenharmony_ci 947e41f4b71Sopenharmony_ci**参数:** 948e41f4b71Sopenharmony_ci 949e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 950e41f4b71Sopenharmony_ci| ------ | ------------------------ | ---- | ------------------------------------------------------------ | 951e41f4b71Sopenharmony_ci| value | [Font](ts-types.md#font) | 是 | 设置Swiper组件数字导航点的字体样式。<br/>默认值:<br/>{ size: 14, weight: FontWeight.Normal } | 952e41f4b71Sopenharmony_ci 953e41f4b71Sopenharmony_ci### selectedDigitFont 954e41f4b71Sopenharmony_ci 955e41f4b71Sopenharmony_ciselectedDigitFont(value: Font) 956e41f4b71Sopenharmony_ci 957e41f4b71Sopenharmony_ci选中Swiper组件数字导航点的字体样式。 958e41f4b71Sopenharmony_ci 959e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 960e41f4b71Sopenharmony_ci 961e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 962e41f4b71Sopenharmony_ci 963e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 964e41f4b71Sopenharmony_ci 965e41f4b71Sopenharmony_ci**参数:** 966e41f4b71Sopenharmony_ci 967e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 968e41f4b71Sopenharmony_ci| ------ | ------------------------ | ---- | ------------------------------------------------------------ | 969e41f4b71Sopenharmony_ci| value | [Font](ts-types.md#font) | 是 | 设置选中Swiper组件数字导航点的字体样式。<br/>默认值:<br/>{ size: 14, weight: FontWeight.Normal } | 970e41f4b71Sopenharmony_ci 971e41f4b71Sopenharmony_ci>**说明:** 972e41f4b71Sopenharmony_ci> 973e41f4b71Sopenharmony_ci> 按组翻页时,数字导航点显示的子节点数量,不包括占位节点。 974e41f4b71Sopenharmony_ci 975e41f4b71Sopenharmony_ci### constructor 976e41f4b71Sopenharmony_ci 977e41f4b71Sopenharmony_ciconstructor() 978e41f4b71Sopenharmony_ci 979e41f4b71Sopenharmony_ciDigitIndicator的构造函数。 980e41f4b71Sopenharmony_ci 981e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 982e41f4b71Sopenharmony_ci 983e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 984e41f4b71Sopenharmony_ci 985e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 986e41f4b71Sopenharmony_ci 987e41f4b71Sopenharmony_ci## ArrowStyle<sup>10+</sup>对象说明 988e41f4b71Sopenharmony_ci左右箭头属性。 989e41f4b71Sopenharmony_ci 990e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 991e41f4b71Sopenharmony_ci 992e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 993e41f4b71Sopenharmony_ci 994e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 995e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------------- | ---- | ---------------------------------------- | 996e41f4b71Sopenharmony_ci| showBackground | boolean | 否 | 设置箭头底板是否显示。<br/>默认值:false | 997e41f4b71Sopenharmony_ci| isSidebarMiddle | boolean | 否 | 设置箭头显示位置。<br/>默认值:false <br/>默认显示在导航点指示器两侧。 | 998e41f4b71Sopenharmony_ci| backgroundSize | [Length](ts-types.md#length) | 否 | 设置底板大小。<br/>在导航点两侧显示:<br/>默认值:24vp<br/>在组件两侧显示:<br/>默认值:32vp<br/>不支持设置百分比。 | 999e41f4b71Sopenharmony_ci| backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | 设置底板颜色。<br/>在导航点两侧显示:<br/>默认值:'\#00000000'<br/>在组件两侧显示:<br/>默认值:'\#19182431' | 1000e41f4b71Sopenharmony_ci| arrowSize | [Length](ts-types.md#length) | 否 | 设置箭头大小。<br/>在导航点两侧显示时:<br/>默认值:18vp<br/>在组件两侧显示时:<br/>默认值:24vp<br/>**说明:**<br/>showBackground为true时,arrowSize为backgroundSize的3/4。<br/>不支持设置百分比。 | 1001e41f4b71Sopenharmony_ci| arrowColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | 设置箭头颜色。<br/>默认值:'\#182431' | 1002e41f4b71Sopenharmony_ci 1003e41f4b71Sopenharmony_ci## SwiperAutoFill<sup>10+</sup>对象说明 1004e41f4b71Sopenharmony_ci 1005e41f4b71Sopenharmony_ci自适应属性。 1006e41f4b71Sopenharmony_ci 1007e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 1008e41f4b71Sopenharmony_ci 1009e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1010e41f4b71Sopenharmony_ci 1011e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1012e41f4b71Sopenharmony_ci 1013e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1014e41f4b71Sopenharmony_ci| ------- | -------------------- | ------ | ------------------------------------ | 1015e41f4b71Sopenharmony_ci| minSize | [VP](ts-types.md#vp10) | 是 | 设置元素显示最小宽度。<br/>默认值:0 | 1016e41f4b71Sopenharmony_ci 1017e41f4b71Sopenharmony_ci## 事件 1018e41f4b71Sopenharmony_ci 1019e41f4b71Sopenharmony_ci除支持[通用事件](ts-universal-events-click.md)外,还支持以下事件: 1020e41f4b71Sopenharmony_ci 1021e41f4b71Sopenharmony_ci### onChange 1022e41f4b71Sopenharmony_ci 1023e41f4b71Sopenharmony_cionChange(event: (index: number) => void) 1024e41f4b71Sopenharmony_ci 1025e41f4b71Sopenharmony_ci当前显示的子组件索引变化时触发该事件,返回值为当前显示的子组件的索引值。 1026e41f4b71Sopenharmony_ci 1027e41f4b71Sopenharmony_ciSwiper组件结合LazyForEach使用时,不能在onChange事件里触发子页面UI的刷新。 1028e41f4b71Sopenharmony_ci 1029e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 1030e41f4b71Sopenharmony_ci 1031e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1032e41f4b71Sopenharmony_ci 1033e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1034e41f4b71Sopenharmony_ci 1035e41f4b71Sopenharmony_ci**参数:** 1036e41f4b71Sopenharmony_ci 1037e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1038e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------- | 1039e41f4b71Sopenharmony_ci| index | number | 是 | 当前显示元素的索引。 | 1040e41f4b71Sopenharmony_ci 1041e41f4b71Sopenharmony_ci### onAnimationStart<sup>9+</sup> 1042e41f4b71Sopenharmony_ci 1043e41f4b71Sopenharmony_cionAnimationStart(event: (index: number, targetIndex: number, extraInfo: SwiperAnimationEvent) => void) 1044e41f4b71Sopenharmony_ci 1045e41f4b71Sopenharmony_ci切换动画开始时触发该回调。参数为动画开始前的index值(不是最终结束动画的index值),多列Swiper时,index为最左侧组件的索引。 1046e41f4b71Sopenharmony_ci 1047e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 1048e41f4b71Sopenharmony_ci 1049e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1050e41f4b71Sopenharmony_ci 1051e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1052e41f4b71Sopenharmony_ci 1053e41f4b71Sopenharmony_ci**参数:** 1054e41f4b71Sopenharmony_ci 1055e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1056e41f4b71Sopenharmony_ci| ------------------------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 1057e41f4b71Sopenharmony_ci| index | number | 是 | 当前显示元素的索引。 | 1058e41f4b71Sopenharmony_ci| targetIndex<sup>10+</sup> | number | 是 | 切换动画目标元素的索引。 | 1059e41f4b71Sopenharmony_ci| extraInfo<sup>10+</sup> | [SwiperAnimationEvent](#swiperanimationevent10对象说明) | 是 | 动画相关信息,包括主轴方向上当前显示元素和目标元素相对Swiper起始位置的位移,以及离手速度。 | 1060e41f4b71Sopenharmony_ci 1061e41f4b71Sopenharmony_ci>**说明:** 1062e41f4b71Sopenharmony_ci> 1063e41f4b71Sopenharmony_ci>- 当翻页动画时长为0时,只有以下场景会触发该回调:滑动翻页、自动轮播、调用SwiperController.showNext()和SwiperController.showPrevious()接口以及手指点击导航点翻页。 1064e41f4b71Sopenharmony_ci 1065e41f4b71Sopenharmony_ci### onAnimationEnd<sup>9+</sup> 1066e41f4b71Sopenharmony_ci 1067e41f4b71Sopenharmony_cionAnimationEnd(event: (index: number, extraInfo: SwiperAnimationEvent) => void) 1068e41f4b71Sopenharmony_ci 1069e41f4b71Sopenharmony_ci切换动画结束时触发该回调。 1070e41f4b71Sopenharmony_ci 1071e41f4b71Sopenharmony_ci当Swiper切换动效结束时触发,包括动画过程中手势中断,通过SwiperController调用finishAnimation。参数为动画结束后的index值,多列Swiper时,index为最左侧组件的索引。 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ci**卡片能力:** 从API version 10开始,该接口支持在ArkTS卡片中使用。 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci**参数:** 1080e41f4b71Sopenharmony_ci 1081e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1082e41f4b71Sopenharmony_ci| ----------------------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 1083e41f4b71Sopenharmony_ci| index | number | 是 | 当前显示元素的索引。 | 1084e41f4b71Sopenharmony_ci| extraInfo<sup>10+</sup> | [SwiperAnimationEvent](#swiperanimationevent10对象说明) | 是 | 动画相关信息,只返回主轴方向上当前显示元素相对于Swiper起始位置的位移。 | 1085e41f4b71Sopenharmony_ci 1086e41f4b71Sopenharmony_ci>**说明:** 1087e41f4b71Sopenharmony_ci> 1088e41f4b71Sopenharmony_ci>- 当翻页动画时长为0时,只有以下场景会触发该回调:滑动翻页、自动轮播、调用SwiperController.showNext()和SwiperController.showPrevious()接口以及手指点击导航点翻页。 1089e41f4b71Sopenharmony_ci 1090e41f4b71Sopenharmony_ci### onGestureSwipe<sup>10+</sup> 1091e41f4b71Sopenharmony_ci 1092e41f4b71Sopenharmony_cionGestureSwipe(event: (index: number, extraInfo: SwiperAnimationEvent) => void) 1093e41f4b71Sopenharmony_ci 1094e41f4b71Sopenharmony_ci在页面跟手滑动过程中,逐帧触发该回调。多列Swiper时,index为最左侧组件的索引。 1095e41f4b71Sopenharmony_ci 1096e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1097e41f4b71Sopenharmony_ci 1098e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1099e41f4b71Sopenharmony_ci 1100e41f4b71Sopenharmony_ci**参数:** 1101e41f4b71Sopenharmony_ci 1102e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1103e41f4b71Sopenharmony_ci| --------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 1104e41f4b71Sopenharmony_ci| index | number | 是 | 当前显示元素的索引。 | 1105e41f4b71Sopenharmony_ci| extraInfo | [SwiperAnimationEvent](#swiperanimationevent10对象说明) | 是 | 动画相关信息,只返回主轴方向上当前显示元素相对于Swiper起始位置的位移。 | 1106e41f4b71Sopenharmony_ci 1107e41f4b71Sopenharmony_ci### customContentTransition<sup>12+</sup> 1108e41f4b71Sopenharmony_ci 1109e41f4b71Sopenharmony_cicustomContentTransition(transition: SwiperContentAnimatedTransition) 1110e41f4b71Sopenharmony_ci 1111e41f4b71Sopenharmony_ci自定义Swiper页面切换动画。在页面跟手滑动和离手后执行切换动画的过程中,会对视窗内所有页面逐帧触发回调,开发者可以在回调中设置透明度、缩放比例、位移等属性来自定义切换动画。 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ci使用说明: 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci1、循环场景下,设置prevMargin和nextMargin属性,使得Swiper前后端显示同一页面时,该接口不生效。<br>2、在页面跟手滑动和离手后执行切换动画的过程中,会对视窗内所有页面逐帧触发[SwiperContentTransitionProxy](#swipercontenttransitionproxy12对象说明)回调。例如,当视窗内有下标为0、1的两个页面时,会每帧触发两次index值分别为0和1的回调。<br>3、设置displayCount属性的swipeByGroup参数为true时,若同组中至少有一个页面在视窗内时,则会对同组中所有页面触发回调,若同组所有页面均不在视窗内时,则会一起下渲染树。<br>4、在页面跟手滑动和离手后执行切换动画的过程中,默认动画(页面滑动)依然会发生,若希望页面不滑动,可以设置主轴方向上负的位移(translate属性)来抵消页面滑动。例如:当displayCount属性值为2,视窗内有下标为0、1的两个页面时,页面水平滑动过程中,可以逐帧设置第0页的translate属性在x轴上的值为-position * mainAxisLength来抵消第0页的位移,设置第1页的translate属性在x轴上的值为-(position - 1) * mainAxisLength来抵消第1页的位移。 1116e41f4b71Sopenharmony_ci 1117e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1118e41f4b71Sopenharmony_ci 1119e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1120e41f4b71Sopenharmony_ci 1121e41f4b71Sopenharmony_ci**参数:** 1122e41f4b71Sopenharmony_ci 1123e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1124e41f4b71Sopenharmony_ci| ------ | ---- | ---- | ---- | 1125e41f4b71Sopenharmony_ci| transition | [SwiperContentAnimatedTransition](#swipercontentanimatedtransition12对象说明) | 是 | Swiper自定义切换动画相关信息。 | 1126e41f4b71Sopenharmony_ci 1127e41f4b71Sopenharmony_ci### onContentDidScroll<sup>12+</sup> 1128e41f4b71Sopenharmony_ci 1129e41f4b71Sopenharmony_cionContentDidScroll(handler: ContentDidScrollCallback) 1130e41f4b71Sopenharmony_ci 1131e41f4b71Sopenharmony_ci监听Swiper页面滑动事件。 1132e41f4b71Sopenharmony_ci 1133e41f4b71Sopenharmony_ci使用说明: 1134e41f4b71Sopenharmony_ci 1135e41f4b71Sopenharmony_ci1、循环场景下,设置prevMargin和nextMargin属性,使得Swiper前后端显示同一页面时,该接口不生效。<br>2、在页面滑动过程中,会对视窗内所有页面逐帧触发[ContentDidScrollCallback](#contentdidscrollcallback12)回调。例如,当视窗内有下标为0、1的两个页面时,会每帧触发两次index值分别为0和1的回调。<br>3、设置displayCount属性的swipeByGroup参数为true时,若同组中至少有一个页面在视窗内时,则会对同组中所有页面触发回调。 1136e41f4b71Sopenharmony_ci 1137e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1138e41f4b71Sopenharmony_ci 1139e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1140e41f4b71Sopenharmony_ci 1141e41f4b71Sopenharmony_ci**参数:** 1142e41f4b71Sopenharmony_ci 1143e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1144e41f4b71Sopenharmony_ci| ------ | ---- | ---- | ---- | 1145e41f4b71Sopenharmony_ci| handler | [ContentDidScrollCallback](#contentdidscrollcallback12) | 是 | Swiper滑动时触发的回调。 | 1146e41f4b71Sopenharmony_ci 1147e41f4b71Sopenharmony_ci## SwiperAnimationEvent<sup>10+</sup>对象说明 1148e41f4b71Sopenharmony_ci 1149e41f4b71Sopenharmony_ciSwiper组件动画相关信息集合。 1150e41f4b71Sopenharmony_ci 1151e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 可选 | 说明 | 1156e41f4b71Sopenharmony_ci| ------------- | ----------- | ---- | ---- |------------------------------- | 1157e41f4b71Sopenharmony_ci| currentOffset | number | 否 | 否 | Swiper当前显示元素在主轴方向上,相对于Swiper起始位置的位移。单位VP,默认值为0。| 1158e41f4b71Sopenharmony_ci| targetOffset | number | 否 | 否 | Swiper动画目标元素在主轴方向上,相对于Swiper起始位置的位移。单位VP,默认值为0。| 1159e41f4b71Sopenharmony_ci| velocity | number | 否 | 否 | Swiper离手动画开始时的离手速度。单位VP/S,默认值为0。| 1160e41f4b71Sopenharmony_ci 1161e41f4b71Sopenharmony_ci## SwiperContentAnimatedTransition<sup>12+</sup>对象说明 1162e41f4b71Sopenharmony_ci 1163e41f4b71Sopenharmony_ciSwiper自定义切换动画相关信息。 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1166e41f4b71Sopenharmony_ci 1167e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1168e41f4b71Sopenharmony_ci 1169e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1170e41f4b71Sopenharmony_ci| ------ | ---- | ---- | ---- | 1171e41f4b71Sopenharmony_ci| timeout | number | 否 | Swiper自定义切换动画超时时间。从页面执行默认动画(页面滑动)至移出视窗外的第一帧开始计时,如果到达该时间后,开发者仍未调用[SwiperContentTransitionProxy](#swipercontenttransitionproxy12对象说明)的finishTransition接口通知Swiper组件此页面的自定义动画已结束,那么组件就会认为此页面的自定义动画已结束,立即将该页面节点下渲染树。单位ms,默认值为0。 | 1172e41f4b71Sopenharmony_ci| transition | Callback<[SwiperContentTransitionProxy](#swipercontenttransitionproxy12对象说明)> | 是 | 自定义切换动画具体内容。 | 1173e41f4b71Sopenharmony_ci 1174e41f4b71Sopenharmony_ci## SwiperContentTransitionProxy<sup>12+</sup>对象说明 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_ciSwiper自定义切换动画执行过程中,返回给开发者的proxy对象。开发者可通过该对象获取自定义动画视窗内的页面信息,同时,也可以通过调用该对象的finishTransition接口通知Swiper组件页面自定义动画已结束。 1177e41f4b71Sopenharmony_ci 1178e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1179e41f4b71Sopenharmony_ci 1180e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1181e41f4b71Sopenharmony_ci 1182e41f4b71Sopenharmony_ci### 属性 1183e41f4b71Sopenharmony_ci 1184e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 可选 | 说明 | 1185e41f4b71Sopenharmony_ci| ---- | ---- | --- | ---- | --- | 1186e41f4b71Sopenharmony_ci| selectedIndex | number | 否 | 否 | 当前选中页面的索引。 | 1187e41f4b71Sopenharmony_ci| index | number | 否 | 否 | 视窗内页面的索引。 | 1188e41f4b71Sopenharmony_ci| position | number | 否 | 否 | index页面相对于Swiper主轴起始位置(selectedIndex对应页面的起始位置)的移动比例。 | 1189e41f4b71Sopenharmony_ci| mainAxisLength | number | 否 | 否 | index对应页面在主轴方向上的长度。 | 1190e41f4b71Sopenharmony_ci 1191e41f4b71Sopenharmony_ci>**说明:** 1192e41f4b71Sopenharmony_ci> 1193e41f4b71Sopenharmony_ci>- 例如,当前选中的子组件的索引为0,从第0页切换到第1页的动画过程中,每帧都会对视窗内所有页面触发回调,当视窗内有第0页和第1页两页时,每帧会触发两次回调。其中,第一次回调的selectedIndex为0、index为0、position为当前帧第0页相对于动画开始前第0页的移动比例,mainAxisLength为主轴方向上第0页的长度。第二次回调的selectedIndex仍为0、index为1、position为当前帧第1页相对于动画开始前第0页的移动比例,mainAxisLength为主轴方向上第1页的长度。 1194e41f4b71Sopenharmony_ci> 1195e41f4b71Sopenharmony_ci>- 若动画曲线为弹簧插值曲线,从第0页切换到第1页的动画过程中,可能会因为离手时的位置和速度,先过滑到第2页,再回弹到第1页,该过程中每帧会对视窗内第1页和第2页触发回调。 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ci 1198e41f4b71Sopenharmony_ci### finishTransition<sup>12+</sup> 1199e41f4b71Sopenharmony_ci 1200e41f4b71Sopenharmony_cifinishTransition(): void 1201e41f4b71Sopenharmony_ci 1202e41f4b71Sopenharmony_ci通知Swiper组件,此页面的自定义动画已结束。 1203e41f4b71Sopenharmony_ci 1204e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1205e41f4b71Sopenharmony_ci 1206e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1207e41f4b71Sopenharmony_ci 1208e41f4b71Sopenharmony_ci## ContentDidScrollCallback<sup>12+</sup> 1209e41f4b71Sopenharmony_ci 1210e41f4b71Sopenharmony_citype ContentDidScrollCallback = (selectedIndex: number, index: number, position: number, mainAxisLength: number) => void 1211e41f4b71Sopenharmony_ci 1212e41f4b71Sopenharmony_ciSwiper滑动时触发的回调,参数可参考[SwiperContentTransitionProxy](#swipercontenttransitionproxy12对象说明)中的说明。 1213e41f4b71Sopenharmony_ci 1214e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1215e41f4b71Sopenharmony_ci 1216e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 1217e41f4b71Sopenharmony_ci 1218e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1219e41f4b71Sopenharmony_ci| ------ | ---- | ---- | ---- | 1220e41f4b71Sopenharmony_ci| selectedIndex | number | 是 | 当前选中页面的索引。 | 1221e41f4b71Sopenharmony_ci| index | number | 是 | 视窗内页面的索引。 | 1222e41f4b71Sopenharmony_ci| position | number | 是 | index页面相对于Swiper主轴起始位置(selectedIndex对应页面的起始位置)的移动比例。 | 1223e41f4b71Sopenharmony_ci| mainAxisLength | number | 是 | index对应页面在主轴方向上的长度。 | 1224e41f4b71Sopenharmony_ci 1225e41f4b71Sopenharmony_ci## 示例 1226e41f4b71Sopenharmony_ci 1227e41f4b71Sopenharmony_ci### 示例1 1228e41f4b71Sopenharmony_ci该示例实现了通过indicatorInteractive控制导航点交互功能。 1229e41f4b71Sopenharmony_ci```ts 1230e41f4b71Sopenharmony_ci// xxx.ets 1231e41f4b71Sopenharmony_ciclass MyDataSource implements IDataSource { 1232e41f4b71Sopenharmony_ci private list: number[] = [] 1233e41f4b71Sopenharmony_ci 1234e41f4b71Sopenharmony_ci constructor(list: number[]) { 1235e41f4b71Sopenharmony_ci this.list = list 1236e41f4b71Sopenharmony_ci } 1237e41f4b71Sopenharmony_ci 1238e41f4b71Sopenharmony_ci totalCount(): number { 1239e41f4b71Sopenharmony_ci return this.list.length 1240e41f4b71Sopenharmony_ci } 1241e41f4b71Sopenharmony_ci 1242e41f4b71Sopenharmony_ci getData(index: number): number { 1243e41f4b71Sopenharmony_ci return this.list[index] 1244e41f4b71Sopenharmony_ci } 1245e41f4b71Sopenharmony_ci 1246e41f4b71Sopenharmony_ci registerDataChangeListener(listener: DataChangeListener): void { 1247e41f4b71Sopenharmony_ci } 1248e41f4b71Sopenharmony_ci 1249e41f4b71Sopenharmony_ci unregisterDataChangeListener() { 1250e41f4b71Sopenharmony_ci } 1251e41f4b71Sopenharmony_ci} 1252e41f4b71Sopenharmony_ci 1253e41f4b71Sopenharmony_ci@Entry 1254e41f4b71Sopenharmony_ci@Component 1255e41f4b71Sopenharmony_cistruct SwiperExample { 1256e41f4b71Sopenharmony_ci private swiperController: SwiperController = new SwiperController() 1257e41f4b71Sopenharmony_ci private data: MyDataSource = new MyDataSource([]) 1258e41f4b71Sopenharmony_ci 1259e41f4b71Sopenharmony_ci aboutToAppear(): void { 1260e41f4b71Sopenharmony_ci let list: number[] = [] 1261e41f4b71Sopenharmony_ci for (let i = 1; i <= 10; i++) { 1262e41f4b71Sopenharmony_ci list.push(i); 1263e41f4b71Sopenharmony_ci } 1264e41f4b71Sopenharmony_ci this.data = new MyDataSource(list) 1265e41f4b71Sopenharmony_ci } 1266e41f4b71Sopenharmony_ci 1267e41f4b71Sopenharmony_ci build() { 1268e41f4b71Sopenharmony_ci Column({ space: 5 }) { 1269e41f4b71Sopenharmony_ci Swiper(this.swiperController) { 1270e41f4b71Sopenharmony_ci LazyForEach(this.data, (item: string) => { 1271e41f4b71Sopenharmony_ci Text(item.toString()) 1272e41f4b71Sopenharmony_ci .width('90%') 1273e41f4b71Sopenharmony_ci .height(160) 1274e41f4b71Sopenharmony_ci .backgroundColor(0xAFEEEE) 1275e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 1276e41f4b71Sopenharmony_ci .fontSize(30) 1277e41f4b71Sopenharmony_ci }, (item: string) => item) 1278e41f4b71Sopenharmony_ci } 1279e41f4b71Sopenharmony_ci .cachedCount(2) 1280e41f4b71Sopenharmony_ci .index(1) 1281e41f4b71Sopenharmony_ci .autoPlay(true) 1282e41f4b71Sopenharmony_ci .interval(4000) 1283e41f4b71Sopenharmony_ci .loop(true) 1284e41f4b71Sopenharmony_ci .indicatorInteractive(true) 1285e41f4b71Sopenharmony_ci .duration(1000) 1286e41f4b71Sopenharmony_ci .itemSpace(0) 1287e41f4b71Sopenharmony_ci .indicator( // 设置圆点导航点样式 1288e41f4b71Sopenharmony_ci new DotIndicator() 1289e41f4b71Sopenharmony_ci .itemWidth(15) 1290e41f4b71Sopenharmony_ci .itemHeight(15) 1291e41f4b71Sopenharmony_ci .selectedItemWidth(15) 1292e41f4b71Sopenharmony_ci .selectedItemHeight(15) 1293e41f4b71Sopenharmony_ci .color(Color.Gray) 1294e41f4b71Sopenharmony_ci .selectedColor(Color.Blue)) 1295e41f4b71Sopenharmony_ci .displayArrow({ // 设置导航点箭头样式 1296e41f4b71Sopenharmony_ci showBackground: true, 1297e41f4b71Sopenharmony_ci isSidebarMiddle: true, 1298e41f4b71Sopenharmony_ci backgroundSize: 24, 1299e41f4b71Sopenharmony_ci backgroundColor: Color.White, 1300e41f4b71Sopenharmony_ci arrowSize: 18, 1301e41f4b71Sopenharmony_ci arrowColor: Color.Blue 1302e41f4b71Sopenharmony_ci }, false) 1303e41f4b71Sopenharmony_ci .curve(Curve.Linear) 1304e41f4b71Sopenharmony_ci .onChange((index: number) => { 1305e41f4b71Sopenharmony_ci console.info(index.toString()) 1306e41f4b71Sopenharmony_ci }) 1307e41f4b71Sopenharmony_ci .onGestureSwipe((index: number, extraInfo: SwiperAnimationEvent) => { 1308e41f4b71Sopenharmony_ci console.info("index: " + index) 1309e41f4b71Sopenharmony_ci console.info("current offset: " + extraInfo.currentOffset) 1310e41f4b71Sopenharmony_ci }) 1311e41f4b71Sopenharmony_ci .onAnimationStart((index: number, targetIndex: number, extraInfo: SwiperAnimationEvent) => { 1312e41f4b71Sopenharmony_ci console.info("index: " + index) 1313e41f4b71Sopenharmony_ci console.info("targetIndex: " + targetIndex) 1314e41f4b71Sopenharmony_ci console.info("current offset: " + extraInfo.currentOffset) 1315e41f4b71Sopenharmony_ci console.info("target offset: " + extraInfo.targetOffset) 1316e41f4b71Sopenharmony_ci console.info("velocity: " + extraInfo.velocity) 1317e41f4b71Sopenharmony_ci }) 1318e41f4b71Sopenharmony_ci .onAnimationEnd((index: number, extraInfo: SwiperAnimationEvent) => { 1319e41f4b71Sopenharmony_ci console.info("index: " + index) 1320e41f4b71Sopenharmony_ci console.info("current offset: " + extraInfo.currentOffset) 1321e41f4b71Sopenharmony_ci }) 1322e41f4b71Sopenharmony_ci 1323e41f4b71Sopenharmony_ci Row({ space: 12 }) { 1324e41f4b71Sopenharmony_ci Button('showNext') 1325e41f4b71Sopenharmony_ci .onClick(() => { 1326e41f4b71Sopenharmony_ci this.swiperController.showNext() 1327e41f4b71Sopenharmony_ci }) 1328e41f4b71Sopenharmony_ci Button('showPrevious') 1329e41f4b71Sopenharmony_ci .onClick(() => { 1330e41f4b71Sopenharmony_ci this.swiperController.showPrevious() 1331e41f4b71Sopenharmony_ci }) 1332e41f4b71Sopenharmony_ci }.margin(5) 1333e41f4b71Sopenharmony_ci }.width('100%') 1334e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1335e41f4b71Sopenharmony_ci } 1336e41f4b71Sopenharmony_ci} 1337e41f4b71Sopenharmony_ci``` 1338e41f4b71Sopenharmony_ci 1339e41f4b71Sopenharmony_ci 1340e41f4b71Sopenharmony_ci 1341e41f4b71Sopenharmony_ci### 示例2 1342e41f4b71Sopenharmony_ci该示例演示了使用数字指示器的效果和功能。 1343e41f4b71Sopenharmony_ci```ts 1344e41f4b71Sopenharmony_ci// xxx.ets 1345e41f4b71Sopenharmony_ciclass MyDataSource implements IDataSource { 1346e41f4b71Sopenharmony_ci private list: number[] = [] 1347e41f4b71Sopenharmony_ci 1348e41f4b71Sopenharmony_ci constructor(list: number[]) { 1349e41f4b71Sopenharmony_ci this.list = list 1350e41f4b71Sopenharmony_ci } 1351e41f4b71Sopenharmony_ci 1352e41f4b71Sopenharmony_ci totalCount(): number { 1353e41f4b71Sopenharmony_ci return this.list.length 1354e41f4b71Sopenharmony_ci } 1355e41f4b71Sopenharmony_ci 1356e41f4b71Sopenharmony_ci getData(index: number): number { 1357e41f4b71Sopenharmony_ci return this.list[index] 1358e41f4b71Sopenharmony_ci } 1359e41f4b71Sopenharmony_ci 1360e41f4b71Sopenharmony_ci registerDataChangeListener(listener: DataChangeListener): void { 1361e41f4b71Sopenharmony_ci } 1362e41f4b71Sopenharmony_ci 1363e41f4b71Sopenharmony_ci unregisterDataChangeListener() { 1364e41f4b71Sopenharmony_ci } 1365e41f4b71Sopenharmony_ci} 1366e41f4b71Sopenharmony_ci 1367e41f4b71Sopenharmony_ci@Entry 1368e41f4b71Sopenharmony_ci@Component 1369e41f4b71Sopenharmony_cistruct SwiperExample { 1370e41f4b71Sopenharmony_ci private swiperController: SwiperController = new SwiperController() 1371e41f4b71Sopenharmony_ci private data: MyDataSource = new MyDataSource([]) 1372e41f4b71Sopenharmony_ci 1373e41f4b71Sopenharmony_ci aboutToAppear(): void { 1374e41f4b71Sopenharmony_ci let list: number[] = [] 1375e41f4b71Sopenharmony_ci for (let i = 1; i <= 10; i++) { 1376e41f4b71Sopenharmony_ci list.push(i); 1377e41f4b71Sopenharmony_ci } 1378e41f4b71Sopenharmony_ci this.data = new MyDataSource(list) 1379e41f4b71Sopenharmony_ci } 1380e41f4b71Sopenharmony_ci 1381e41f4b71Sopenharmony_ci build() { 1382e41f4b71Sopenharmony_ci Column({ space: 5 }) { 1383e41f4b71Sopenharmony_ci Swiper(this.swiperController) { 1384e41f4b71Sopenharmony_ci LazyForEach(this.data, (item: string) => { 1385e41f4b71Sopenharmony_ci Text(item.toString()) 1386e41f4b71Sopenharmony_ci .width('90%') 1387e41f4b71Sopenharmony_ci .height(160) 1388e41f4b71Sopenharmony_ci .backgroundColor(0xAFEEEE) 1389e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 1390e41f4b71Sopenharmony_ci .fontSize(30) 1391e41f4b71Sopenharmony_ci }, (item: string) => item) 1392e41f4b71Sopenharmony_ci } 1393e41f4b71Sopenharmony_ci .cachedCount(2) 1394e41f4b71Sopenharmony_ci .index(1) 1395e41f4b71Sopenharmony_ci .autoPlay(true) 1396e41f4b71Sopenharmony_ci .interval(4000) 1397e41f4b71Sopenharmony_ci .indicator(Indicator.digit() // 设置数字导航点样式 1398e41f4b71Sopenharmony_ci .top(200) 1399e41f4b71Sopenharmony_ci .fontColor(Color.Gray) 1400e41f4b71Sopenharmony_ci .selectedFontColor(Color.Gray) 1401e41f4b71Sopenharmony_ci .digitFont({ size: 20, weight: FontWeight.Bold }) 1402e41f4b71Sopenharmony_ci .selectedDigitFont({ size: 20, weight: FontWeight.Normal })) 1403e41f4b71Sopenharmony_ci .loop(true) 1404e41f4b71Sopenharmony_ci .duration(1000) 1405e41f4b71Sopenharmony_ci .itemSpace(0) 1406e41f4b71Sopenharmony_ci .displayArrow(true, false) 1407e41f4b71Sopenharmony_ci 1408e41f4b71Sopenharmony_ci Row({ space: 12 }) { 1409e41f4b71Sopenharmony_ci Button('showNext') 1410e41f4b71Sopenharmony_ci .onClick(() => { 1411e41f4b71Sopenharmony_ci this.swiperController.showNext() 1412e41f4b71Sopenharmony_ci }) 1413e41f4b71Sopenharmony_ci Button('showPrevious') 1414e41f4b71Sopenharmony_ci .onClick(() => { 1415e41f4b71Sopenharmony_ci this.swiperController.showPrevious() 1416e41f4b71Sopenharmony_ci }) 1417e41f4b71Sopenharmony_ci }.margin(5) 1418e41f4b71Sopenharmony_ci }.width('100%') 1419e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1420e41f4b71Sopenharmony_ci } 1421e41f4b71Sopenharmony_ci} 1422e41f4b71Sopenharmony_ci``` 1423e41f4b71Sopenharmony_ci 1424e41f4b71Sopenharmony_ci 1425e41f4b71Sopenharmony_ci### 示例3 1426e41f4b71Sopenharmony_ci该示例通过dislayCount属性实现了按组翻页的效果。 1427e41f4b71Sopenharmony_ci```ts 1428e41f4b71Sopenharmony_ci// xxx.ets 1429e41f4b71Sopenharmony_ciclass MyDataSource implements IDataSource { 1430e41f4b71Sopenharmony_ci private list: number[] = [] 1431e41f4b71Sopenharmony_ci 1432e41f4b71Sopenharmony_ci constructor(list: number[]) { 1433e41f4b71Sopenharmony_ci this.list = list 1434e41f4b71Sopenharmony_ci } 1435e41f4b71Sopenharmony_ci 1436e41f4b71Sopenharmony_ci totalCount(): number { 1437e41f4b71Sopenharmony_ci return this.list.length 1438e41f4b71Sopenharmony_ci } 1439e41f4b71Sopenharmony_ci 1440e41f4b71Sopenharmony_ci getData(index: number): number { 1441e41f4b71Sopenharmony_ci return this.list[index] 1442e41f4b71Sopenharmony_ci } 1443e41f4b71Sopenharmony_ci 1444e41f4b71Sopenharmony_ci registerDataChangeListener(listener: DataChangeListener): void { 1445e41f4b71Sopenharmony_ci } 1446e41f4b71Sopenharmony_ci 1447e41f4b71Sopenharmony_ci unregisterDataChangeListener() { 1448e41f4b71Sopenharmony_ci } 1449e41f4b71Sopenharmony_ci} 1450e41f4b71Sopenharmony_ci 1451e41f4b71Sopenharmony_ci@Entry 1452e41f4b71Sopenharmony_ci@Component 1453e41f4b71Sopenharmony_cistruct SwiperExample { 1454e41f4b71Sopenharmony_ci private swiperController: SwiperController = new SwiperController() 1455e41f4b71Sopenharmony_ci private data: MyDataSource = new MyDataSource([]) 1456e41f4b71Sopenharmony_ci 1457e41f4b71Sopenharmony_ci aboutToAppear(): void { 1458e41f4b71Sopenharmony_ci let list: number[] = [] 1459e41f4b71Sopenharmony_ci for (let i = 1; i <= 10; i++) { 1460e41f4b71Sopenharmony_ci list.push(i); 1461e41f4b71Sopenharmony_ci } 1462e41f4b71Sopenharmony_ci this.data = new MyDataSource(list) 1463e41f4b71Sopenharmony_ci } 1464e41f4b71Sopenharmony_ci 1465e41f4b71Sopenharmony_ci build() { 1466e41f4b71Sopenharmony_ci Column({ space: 5 }) { 1467e41f4b71Sopenharmony_ci Swiper(this.swiperController) { 1468e41f4b71Sopenharmony_ci LazyForEach(this.data, (item: string) => { 1469e41f4b71Sopenharmony_ci Text(item.toString()) 1470e41f4b71Sopenharmony_ci .width('90%') 1471e41f4b71Sopenharmony_ci .height(160) 1472e41f4b71Sopenharmony_ci .backgroundColor(0xAFEEEE) 1473e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 1474e41f4b71Sopenharmony_ci .fontSize(30) 1475e41f4b71Sopenharmony_ci }, (item: string) => item) 1476e41f4b71Sopenharmony_ci } 1477e41f4b71Sopenharmony_ci .displayCount(3, true) 1478e41f4b71Sopenharmony_ci .autoPlay(true) 1479e41f4b71Sopenharmony_ci .interval(4000) 1480e41f4b71Sopenharmony_ci .loop(true) 1481e41f4b71Sopenharmony_ci .duration(1000) 1482e41f4b71Sopenharmony_ci .itemSpace(10) 1483e41f4b71Sopenharmony_ci .indicator( // 设置圆点导航点样式 1484e41f4b71Sopenharmony_ci new DotIndicator() 1485e41f4b71Sopenharmony_ci .itemWidth(15) 1486e41f4b71Sopenharmony_ci .itemHeight(15) 1487e41f4b71Sopenharmony_ci .selectedItemWidth(15) 1488e41f4b71Sopenharmony_ci .selectedItemHeight(15) 1489e41f4b71Sopenharmony_ci .color(Color.Gray) 1490e41f4b71Sopenharmony_ci .selectedColor(Color.Blue)) 1491e41f4b71Sopenharmony_ci 1492e41f4b71Sopenharmony_ci Row({ space: 12 }) { 1493e41f4b71Sopenharmony_ci Button('showNext') 1494e41f4b71Sopenharmony_ci .onClick(() => { 1495e41f4b71Sopenharmony_ci this.swiperController.showNext() 1496e41f4b71Sopenharmony_ci }) 1497e41f4b71Sopenharmony_ci Button('showPrevious') 1498e41f4b71Sopenharmony_ci .onClick(() => { 1499e41f4b71Sopenharmony_ci this.swiperController.showPrevious() 1500e41f4b71Sopenharmony_ci }) 1501e41f4b71Sopenharmony_ci }.margin(5) 1502e41f4b71Sopenharmony_ci }.width('100%') 1503e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1504e41f4b71Sopenharmony_ci } 1505e41f4b71Sopenharmony_ci} 1506e41f4b71Sopenharmony_ci``` 1507e41f4b71Sopenharmony_ci 1508e41f4b71Sopenharmony_ci 1509e41f4b71Sopenharmony_ci### 示例4 1510e41f4b71Sopenharmony_ci 1511e41f4b71Sopenharmony_ci本示例通过customContentTransition接口实现了自定义Swiper页面切换动画。 1512e41f4b71Sopenharmony_ci 1513e41f4b71Sopenharmony_ci```ts 1514e41f4b71Sopenharmony_ci// xxx.ets 1515e41f4b71Sopenharmony_ci@Entry 1516e41f4b71Sopenharmony_ci@Component 1517e41f4b71Sopenharmony_cistruct SwiperCustomAnimationExample { 1518e41f4b71Sopenharmony_ci private DISPLAY_COUNT: number = 2 1519e41f4b71Sopenharmony_ci private MIN_SCALE: number = 0.75 1520e41f4b71Sopenharmony_ci 1521e41f4b71Sopenharmony_ci @State backgroundColors: Color[] = [Color.Green, Color.Blue, Color.Yellow, Color.Pink, Color.Gray, Color.Orange] 1522e41f4b71Sopenharmony_ci @State opacityList: number[] = [] 1523e41f4b71Sopenharmony_ci @State scaleList: number[] = [] 1524e41f4b71Sopenharmony_ci @State translateList: number[] = [] 1525e41f4b71Sopenharmony_ci @State zIndexList: number[] = [] 1526e41f4b71Sopenharmony_ci 1527e41f4b71Sopenharmony_ci aboutToAppear(): void { 1528e41f4b71Sopenharmony_ci for (let i = 0; i < this.backgroundColors.length; i++) { 1529e41f4b71Sopenharmony_ci this.opacityList.push(1.0) 1530e41f4b71Sopenharmony_ci this.scaleList.push(1.0) 1531e41f4b71Sopenharmony_ci this.translateList.push(0.0) 1532e41f4b71Sopenharmony_ci this.zIndexList.push(0) 1533e41f4b71Sopenharmony_ci } 1534e41f4b71Sopenharmony_ci } 1535e41f4b71Sopenharmony_ci 1536e41f4b71Sopenharmony_ci build() { 1537e41f4b71Sopenharmony_ci Column() { 1538e41f4b71Sopenharmony_ci Swiper() { 1539e41f4b71Sopenharmony_ci ForEach(this.backgroundColors, (backgroundColor: Color, index: number) => { 1540e41f4b71Sopenharmony_ci Text(index.toString()).width('100%').height('100%').fontSize(50).textAlign(TextAlign.Center) 1541e41f4b71Sopenharmony_ci .backgroundColor(backgroundColor) 1542e41f4b71Sopenharmony_ci // 自定义动画变化透明度、缩放页面、抵消系统默认位移、渲染层级等 1543e41f4b71Sopenharmony_ci .opacity(this.opacityList[index]) 1544e41f4b71Sopenharmony_ci .scale({ x: this.scaleList[index], y: this.scaleList[index] }) 1545e41f4b71Sopenharmony_ci .translate({ x: this.translateList[index] }) 1546e41f4b71Sopenharmony_ci .zIndex(this.zIndexList[index]) 1547e41f4b71Sopenharmony_ci }) 1548e41f4b71Sopenharmony_ci } 1549e41f4b71Sopenharmony_ci .height(300) 1550e41f4b71Sopenharmony_ci .indicator(false) 1551e41f4b71Sopenharmony_ci .displayCount(this.DISPLAY_COUNT, true) 1552e41f4b71Sopenharmony_ci .customContentTransition({ 1553e41f4b71Sopenharmony_ci // 页面移除视窗时超时1000ms下渲染树 1554e41f4b71Sopenharmony_ci timeout: 1000, 1555e41f4b71Sopenharmony_ci // 对视窗内所有页面逐帧回调transition,在回调中修改opacity、scale、translate、zIndex等属性值,实现自定义动画 1556e41f4b71Sopenharmony_ci transition: (proxy: SwiperContentTransitionProxy) => { 1557e41f4b71Sopenharmony_ci if (proxy.position <= proxy.index % this.DISPLAY_COUNT || proxy.position >= this.DISPLAY_COUNT + proxy.index % this.DISPLAY_COUNT) { 1558e41f4b71Sopenharmony_ci // 同组页面往左滑或往右完全滑出视窗外时,重置属性值 1559e41f4b71Sopenharmony_ci this.opacityList[proxy.index] = 1.0 1560e41f4b71Sopenharmony_ci this.scaleList[proxy.index] = 1.0 1561e41f4b71Sopenharmony_ci this.translateList[proxy.index] = 0.0 1562e41f4b71Sopenharmony_ci this.zIndexList[proxy.index] = 0 1563e41f4b71Sopenharmony_ci } else { 1564e41f4b71Sopenharmony_ci // 同组页面往右滑且未滑出视窗外时,对同组中左右两个页面,逐帧根据position修改属性值,实现两个页面往Swiper中间靠拢并透明缩放的自定义切换动画 1565e41f4b71Sopenharmony_ci if (proxy.index % this.DISPLAY_COUNT === 0) { 1566e41f4b71Sopenharmony_ci this.opacityList[proxy.index] = 1 - proxy.position / this.DISPLAY_COUNT 1567e41f4b71Sopenharmony_ci this.scaleList[proxy.index] = this.MIN_SCALE + (1 - this.MIN_SCALE) * (1 - proxy.position / this.DISPLAY_COUNT) 1568e41f4b71Sopenharmony_ci this.translateList[proxy.index] = - proxy.position * proxy.mainAxisLength + (1 - this.scaleList[proxy.index]) * proxy.mainAxisLength / 2.0 1569e41f4b71Sopenharmony_ci } else { 1570e41f4b71Sopenharmony_ci this.opacityList[proxy.index] = 1 - (proxy.position - 1) / this.DISPLAY_COUNT 1571e41f4b71Sopenharmony_ci this.scaleList[proxy.index] = this.MIN_SCALE + (1 - this.MIN_SCALE) * (1 - (proxy.position - 1) / this.DISPLAY_COUNT) 1572e41f4b71Sopenharmony_ci this.translateList[proxy.index] = - (proxy.position - 1) * proxy.mainAxisLength - (1 - this.scaleList[proxy.index]) * proxy.mainAxisLength / 2.0 1573e41f4b71Sopenharmony_ci } 1574e41f4b71Sopenharmony_ci this.zIndexList[proxy.index] = -1 1575e41f4b71Sopenharmony_ci } 1576e41f4b71Sopenharmony_ci } 1577e41f4b71Sopenharmony_ci }) 1578e41f4b71Sopenharmony_ci .onContentDidScroll((selectedIndex: number, index: number, position: number, mainAxisLength: number) => { 1579e41f4b71Sopenharmony_ci // 监听Swiper页面滑动事件,在该回调中可以实现自定义导航点切换动画等 1580e41f4b71Sopenharmony_ci console.info("onContentDidScroll selectedIndex: " + selectedIndex + ", index: " + index + ", position: " + position + ", mainAxisLength: " + mainAxisLength) 1581e41f4b71Sopenharmony_ci }) 1582e41f4b71Sopenharmony_ci }.width('100%') 1583e41f4b71Sopenharmony_ci } 1584e41f4b71Sopenharmony_ci} 1585e41f4b71Sopenharmony_ci``` 1586e41f4b71Sopenharmony_ci 1587e41f4b71Sopenharmony_ci 1588e41f4b71Sopenharmony_ci### 示例5 1589e41f4b71Sopenharmony_ci 1590e41f4b71Sopenharmony_ci本示例通过DotIndicator接口的maxDisplayCount属性实现了圆点导航点超长显示动画效果。 1591e41f4b71Sopenharmony_ci 1592e41f4b71Sopenharmony_ci```ts 1593e41f4b71Sopenharmony_ciclass MyDataSource implements IDataSource { 1594e41f4b71Sopenharmony_ci private list: number[] = [] 1595e41f4b71Sopenharmony_ci 1596e41f4b71Sopenharmony_ci constructor(list: number[]) { 1597e41f4b71Sopenharmony_ci this.list = list 1598e41f4b71Sopenharmony_ci } 1599e41f4b71Sopenharmony_ci 1600e41f4b71Sopenharmony_ci totalCount(): number { 1601e41f4b71Sopenharmony_ci return this.list.length 1602e41f4b71Sopenharmony_ci } 1603e41f4b71Sopenharmony_ci 1604e41f4b71Sopenharmony_ci getData(index: number): number { 1605e41f4b71Sopenharmony_ci return this.list[index] 1606e41f4b71Sopenharmony_ci } 1607e41f4b71Sopenharmony_ci 1608e41f4b71Sopenharmony_ci registerDataChangeListener(listener: DataChangeListener): void { 1609e41f4b71Sopenharmony_ci } 1610e41f4b71Sopenharmony_ci 1611e41f4b71Sopenharmony_ci unregisterDataChangeListener() { 1612e41f4b71Sopenharmony_ci } 1613e41f4b71Sopenharmony_ci} 1614e41f4b71Sopenharmony_ci 1615e41f4b71Sopenharmony_ci@Entry 1616e41f4b71Sopenharmony_ci@Component 1617e41f4b71Sopenharmony_cistruct Index { 1618e41f4b71Sopenharmony_ci private swiperController: SwiperController = new SwiperController() 1619e41f4b71Sopenharmony_ci private data: MyDataSource = new MyDataSource([]) 1620e41f4b71Sopenharmony_ci 1621e41f4b71Sopenharmony_ci aboutToAppear(): void { 1622e41f4b71Sopenharmony_ci let list: number[] = [] 1623e41f4b71Sopenharmony_ci for (let i = 1; i <= 15; i++) { 1624e41f4b71Sopenharmony_ci list.push(i); 1625e41f4b71Sopenharmony_ci } 1626e41f4b71Sopenharmony_ci this.data = new MyDataSource(list) 1627e41f4b71Sopenharmony_ci } 1628e41f4b71Sopenharmony_ci 1629e41f4b71Sopenharmony_ci build() { 1630e41f4b71Sopenharmony_ci Column({ space: 5 }) { 1631e41f4b71Sopenharmony_ci Swiper(this.swiperController) { 1632e41f4b71Sopenharmony_ci LazyForEach(this.data, (item: string) => { 1633e41f4b71Sopenharmony_ci Text(item.toString()) 1634e41f4b71Sopenharmony_ci .width('90%') 1635e41f4b71Sopenharmony_ci .height(160) 1636e41f4b71Sopenharmony_ci .backgroundColor(0xAFEEEE) 1637e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 1638e41f4b71Sopenharmony_ci .fontSize(30) 1639e41f4b71Sopenharmony_ci }, (item: string) => item) 1640e41f4b71Sopenharmony_ci } 1641e41f4b71Sopenharmony_ci .cachedCount(2) 1642e41f4b71Sopenharmony_ci .index(5) 1643e41f4b71Sopenharmony_ci .autoPlay(true) 1644e41f4b71Sopenharmony_ci .interval(4000) 1645e41f4b71Sopenharmony_ci .loop(true) 1646e41f4b71Sopenharmony_ci .duration(1000) 1647e41f4b71Sopenharmony_ci .itemSpace(0) 1648e41f4b71Sopenharmony_ci .indicator( // 设置圆点导航点样式 1649e41f4b71Sopenharmony_ci new DotIndicator() 1650e41f4b71Sopenharmony_ci .itemWidth(8) 1651e41f4b71Sopenharmony_ci .itemHeight(8) 1652e41f4b71Sopenharmony_ci .selectedItemWidth(16) 1653e41f4b71Sopenharmony_ci .selectedItemHeight(8) 1654e41f4b71Sopenharmony_ci .color(Color.Gray) 1655e41f4b71Sopenharmony_ci .selectedColor(Color.Blue) 1656e41f4b71Sopenharmony_ci .maxDisplayCount(9)) 1657e41f4b71Sopenharmony_ci .displayArrow({ // 设置导航点箭头样式 1658e41f4b71Sopenharmony_ci showBackground: true, 1659e41f4b71Sopenharmony_ci isSidebarMiddle: true, 1660e41f4b71Sopenharmony_ci backgroundSize: 24, 1661e41f4b71Sopenharmony_ci backgroundColor: Color.White, 1662e41f4b71Sopenharmony_ci arrowSize: 18, 1663e41f4b71Sopenharmony_ci arrowColor: Color.Blue 1664e41f4b71Sopenharmony_ci }, false) 1665e41f4b71Sopenharmony_ci .curve(Curve.Linear) 1666e41f4b71Sopenharmony_ci Row({ space: 12 }) { 1667e41f4b71Sopenharmony_ci Button('showNext') 1668e41f4b71Sopenharmony_ci .onClick(() => { 1669e41f4b71Sopenharmony_ci this.swiperController.showNext() 1670e41f4b71Sopenharmony_ci }) 1671e41f4b71Sopenharmony_ci Button('showPrevious') 1672e41f4b71Sopenharmony_ci .onClick(() => { 1673e41f4b71Sopenharmony_ci this.swiperController.showPrevious() 1674e41f4b71Sopenharmony_ci }) 1675e41f4b71Sopenharmony_ci }.margin(5) 1676e41f4b71Sopenharmony_ci }.width('100%') 1677e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1678e41f4b71Sopenharmony_ci } 1679e41f4b71Sopenharmony_ci} 1680e41f4b71Sopenharmony_ci``` 1681e41f4b71Sopenharmony_ci 1682e41f4b71Sopenharmony_ci 1683