本文篇幅较长,建议点赞收藏,以免找不到哟(^U^)ノ~YO
当路由进行切换时,可以通过在 onTransition 函数中自定义页面入场和页面退场的转场动效。
函数
onTransition()
protected open func onTransition(): Unit
进入此页面或移动到其他页面时实现动画。
自定义类型
PageTransitionEnter
public class PageTransitionEnter {
public init(value: PageTransitionOptions)
public func slide(value: SlideEffect): This
public func translate(x!: Length = 0.vp, y!: Length = 0.vp, z!: Length = 0.vp): This
public func translate(x!: Length = 0.vp, y!: Length = 0.vp, z!: Length = 0.vp): This
public func translate(x!: Int32 = 0, y!: Int32 = 0, z!: Int32 = 0): This
public func translate(x!: CJResource, y!: CJResource, z!: CJResource): This
public func translate(x!: Int64 = 0, y!: Int64 = 0, z!: Int64 = 0): This
public func translate(x!: Float64 = 0.0, y!: Float64 = 0.0, z!: Float64 = 0.0): This
public func translate(value: Length): This
public func translate(value: CJResource): This
public func translate(value: Int64): This
public func translate(value: Float64): This
public func translateX(value: Length): This
public func translateX(value: CJResource): This
public func translateX(value: Int64): This
public func translateX(value: Float64): This
public func translateY(value: Length): This
public func translateY(value: CJResource): This
public func translateY(value: Int64): This
public func translateY(value: Float64): This
public func scale(scaleValue: Float32): This
public func scale(scaleValue: Int32): This
public func scale(x!: Float32 = 1.0, y!: Float32 = 1.0, z!: Float32 = 1.0, centerX!: Length = 50.percent, centerY!: Length = 50.percent): This
public func scale(x!: Float32 = 1.0, y!: Float32 = 1.0, z!: Float32 = 1.0, centerX!: CJResource, centerY!: CJResource): This
public func scaleX(scale: Float32): This
public func scaleX(scale: Int32): This
public func scaleY(scale: Float32): This
public func scaleY(scale: Int32): This
public func opacity(value: Float64): This
public func opacity(value: Int64): This
}
页面的自定义入场动效类型。
init(PageTransitionOptions)
public init(value: PageTransitionOptions)
创建一个 PageTransitionExit 类型的对象。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | PageTransitionOptions | 是 | - | 配置入场动效的参数。 |
slide(SlideEffect)
public func slide(value: SlideEffect): This
设置页面转场时的滑入滑出效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | SlideEffect | 是 | - | 页面转场时的滑入滑出效果。 |
translate(Length, Length, Length)
public func translate(x!: Length = 0.vp, y!: Length = 0.vp, z!: Length = 0.vp): This
设置页面转场时的平移效果,为入场时起点和退场时终点的值,和slide同时设置时默认生效slide。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Length | 否 | 0.vp | 横向的平移距离。 |
y | Length | 否 | 0.vp | 纵向的平移距离。 |
z | Length | 否 | 0.vp | 竖向的平移距离。 |
translate(Float64, Float64, Float64)
public func translate(x!: Float64 = 0.0, y!: Float64 = 0.0, z!: Float64 = 0.0)
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Float64 | 否 | 0.0 | 横向的平移距离。 |
y | Float64 | 否 | 0.0 | 纵向的平移距离。 |
z | Float64 | 否 | 0.0 | 竖向的平移距离。 |
translate(Int32, Int32, Int32)
public func translate(x!: Int32 = 0, y!: Int32 = 0, z!: Int32 = 0): This
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Int32 | 否 | 0 | 横向的平移距离。 |
y | Int32 | 否 | 0 | 纵向的平移距离。 |
z | Int32 | 否 | 0 | 竖向的平移距离。 |
translate(CJResource, CJResource, CJResource)
public func translate(x!: CJResource, y!: CJResource, z!: CJResource): This
设置页面转场时的平移效果,为入场时起点和退场时终点的值,和slide同时设置时默认生效slide。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | CJResource | 是 | - | 横向的平移距离。 |
y | CJResource | 是 | - | 纵向的平移距离。 |
z | CJResource | 是 | - | 竖向的平移距离。 |
translate(Int64, Int64, Int64)
public func translate(x!: Int64 = 0, y!: Int64 = 0, z!: Int64 = 0): This
设置页面转场时的平移效果,为入场时起点和退场时终点的值,和slide同时设置时默认生效slide。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Int64 | 否 | 0 | 横向的平移距离。 |
y | Int64 | 否 | 0 | 纵向的平移距离。 |
z | Int64 | 否 | 0 | 竖向的平移距离。 |
translate(Float64, Float64, Float64)
public func translate(x!: Float64 = 0.0, y!: Float64 = 0.0, z!: Float64 = 0.0): This
设置页面转场时的平移效果,为入场时起点和退场时终点的值,和slide同时设置时默认生效slide。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Float64 | 否 | 0.0 | 横向的平移距离。 |
y | Float64 | 否 | 0.0 | 纵向的平移距离。 |
z | Float64 | 否 | 0.0 | 竖向的平移距离。 |
translate(Length)
public func translate(value: Length): This
设置页面转场时的平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Length | 是 | - | 平移距离。 |
translate(CJResource)
public func translate(value: CJResource): This
设置页面转场时的平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | CJResource | 是 | - | 平移距离。 |
translate(Int64)
public func translate(value: Int64): This
设置页面转场时的平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Int64 | 是 | - | 平移距离。 |
translate(Float64)
设置页面转场时的平移效果。
public func translate(value: Float64): This
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Float64 | 是 | - | 平移距离。 |
translateX(Length)
public func translateX(value: Length): This
设置页面转场时的横向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Length | 是 | - | 横向平移距离。 |
translateX(CJResource)
public func translateX(value: CJResource): This
设置页面转场时的横向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | CJResource | 是 | - | 横向平移距离。 |
translateX(Int64)
public func translateX(value: Int64): This
设置页面转场时的横向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Int64 | 是 | - | 横向平移距离。 |
translateX(Float64)
public func translateX(value: Float64): This
设置页面转场时的横向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Float64 | 是 | - | 横向平移距离。 |
translateY(Length)
public func translateY(value: Length): This
设置页面转场时的纵向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Length | 是 | - | 纵向平移距离。 |
translateY(CJResource)
public func translateY(value: CJResource): This
设置页面转场时的纵向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | CJResource | 是 | - | 纵向平移距离。 |
translateY(Int64)
public func translateY(value: Int64): This
设置页面转场时的纵向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Int64 | 是 | - | 纵向平移距离。 |
translateY(Float64)
public func translateY(value: Float64): This
设置页面转场时的纵向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Float64 | 是 | - | 纵向平移距离。 |
scale(Float32)
public func scale(scaleValue: Float32): This
设置页面转场时的缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scaleValue | Float32 | 是 | - | 放大倍数(或缩小比例)。 |
scale(Int32)
public func scale(scaleValue: Int32): This
设置页面转场时的缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scaleValue | Int32 | 是 | - | 放大倍数(或缩小比例)。 |
scale(Float32, Float32, Float32, Length, Length)
public func scale(
x!: Float32 = 1.0,
y!: Float32 = 1.0,
z!: Float32 = 1.0,
centerX!: Length = 50.percent,
centerY!: Length = 50.percent
): This
设置页面转场时的缩放效果,为入场时起点和退场时终点的值。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Float32 | 否 | 1.0 | 横向放大倍数(或缩小比例)。 |
y | Float32 | 否 | 1.0 | 纵向放大倍数(或缩小比例)。 |
z | Float32 | 否 | 1.0 | 竖向放大倍数(或缩小比例)。 |
centerX | Length | 否 | 50.percent | 中心点坐标。 |
centerY | Length | 否 | 50.percent | 中心点坐标。 |
scale(Float32, Float32, Float32, CJResource, CJResource)
public func scale(
x!: Float32,
y!: Float32,
z!: Float32,
centerX!: CJResource,
centerY!: CJResource
): This
设置页面转场时的缩放效果,为入场时起点和退场时终点的值。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Float32 | 是 | - | 横向放大倍数(或缩小比例)。 |
y | Float32 | 是 | - | 纵向放大倍数(或缩小比例)。 |
z | Float32 | 是 | - | 竖向放大倍数(或缩小比例)。 |
centerX | CJResource | 是 | - | 中心点坐标。 |
centerY | CJResource | 是 | - | 中心点坐标。 |
scaleX(Float32)
public func scaleX(scale: Float32): This
设置页面转场时的横向缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scale | Float32 | 是 | - | 放大倍数(或缩小比例)。 |
scaleX(Int32)
public func scaleX(scale: Int32): This
设置页面转场时的横向缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scale | Int32 | 是 | - | 放大倍数(或缩小比例)。 |
scaleY(Float32)
public func scaleY(scale: Float32): This
设置页面转场时的纵向缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scale | Float32 | 是 | - | 放大倍数(或缩小比例)。 |
scaleY(Int32)
public func scaleY(scale: Int32): This
设置页面转场时的纵向缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scale | Int32 | 是 | - | 放大倍数(或缩小比例)。 |
opacity(Float64)
public func opacity(value: Float64): This
设置入场的起点透明度值或者退场的终点透明度值。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Float64 | 是 | - | 入场的起点透明度值或者退场的终点透明度值。 |
opacity(Int64)
public func opacity(value: Int64): This
设置入场的起点透明度值或者退场的终点透明度值。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Int64 | 是 | - | 入场的起点透明度值或者退场的终点透明度值。 |
PageTransitionExit
public class PageTransitionExit {
public init(value: PageTransitionOptions)
public func slide(value: SlideEffect): This
public func translate(x!: Length = 0.vp, y!: Length = 0.vp, z!: Length = 0.vp): This
public func translate(x!: Length = 0.vp, y!: Length = 0.vp, z!: Length = 0.vp): This
public func translate(x!: Int32 = 0, y!: Int32 = 0, z!: Int32 = 0): This
public func translate(x!: CJResource, y!: CJResource, z!: CJResource): This
public func translate(x!: Int64 = 0, y!: Int64 = 0, z!: Int64 = 0): This
public func translate(x!: Float64 = 0.0, y!: Float64 = 0.0, z!: Float64 = 0.0): This
public func translate(value: Length): This
public func translate(value: CJResource): This
public func translate(value: Int64): This
public func translate(value: Float64): This
public func translateX(value: Length): This
public func translateX(value: CJResource): This
public func translateX(value: Int64): This
public func translateX(value: Float64): This
public func translateY(value: Length): This
public func translateY(value: CJResource): This
public func translateY(value: Int64): This
public func translateY(value: Float64): This
public func scale(scaleValue: Float32): This
public func scale(scaleValue: Int32): This
public func scale(scaleValue: Float32): This
public func scale(scaleValue: Int32): This
public func scale(x!: Float32 = 1.0, y!: Float32 = 1.0, z!: Float32 = 1.0, centerX!: Length = 50.percent, centerY!: Length = 50.percent): This
public func scale(x!: Float32 = 1.0, y!: Float32 = 1.0, z!: Float32 = 1.0, centerX!: CJResource, centerY!: CJResource): This
public func scaleX(scale: Float32): This
public func scaleX(scale: Int32): This
public func scaleY(scale: Float32): This
public func scaleY(scale: Int32): This
public func opacity(value: Float64): This
public func opacity(value: Int64): This
}
页面的自定义退场动效类型。
init(PageTransitionOptions)
public init(value: PageTransitionOptions)
创建一个 PageTransitionExit 类型的对象。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | PageTransitionOptions | 是 | - | 配置退场动效的参数。 |
slide(SlideEffect)
public func slide(value: SlideEffect): This
设置页面转场时的滑入滑出效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | SlideEffect | 是 | - | 页面转场时的滑入滑出效果。 |
translate(Length, Length, Length)
public func translate(x!: Length = 0.vp, y!: Length = 0.vp, z!: Length = 0.vp): This
设置页面转场时的平移效果,为入场时起点和退场时终点的值,和slide同时设置时默认生效slide。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Length | 否 | 0.vp | 横向的平移距离。 |
y | Length | 否 | 0.vp | 纵向的平移距离。 |
z | Length | 否 | 0.vp | 竖向的平移距离。 |
translate(Float64, Float64, Float64)
public func translate(x!: Float64 = 0.0, y!: Float64 = 0.0, z!: Float64 = 0.0)
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Float64 | 否 | 0.0 | 横向的平移距离。 |
y | Float64 | 否 | 0.0 | 纵向的平移距离。 |
z | Float64 | 否 | 0.0 | 竖向的平移距离。 |
translate(Int32, Int32, Int32)
public func translate(x!: Int32 = 0, y!: Int32 = 0, z!: Int32 = 0): This
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Int32 | 否 | 0 | 横向的平移距离。 |
y | Int32 | 否 | 0 | 纵向的平移距离。 |
z | Int32 | 否 | 0 | 竖向的平移距离。 |
translate(CJResource, CJResource, CJResource)
public func translate(x!: CJResource, y!: CJResource, z!: CJResource): This
设置页面转场时的平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | CJResource | 是 | - | 横向的平移距离。 |
y | CJResource | 是 | - | 纵向的平移距离。 |
z | CJResource | 是 | - | 竖向的平移距离。 |
translate(Int64, Int64, Int64)
public func translate(x!: Int64 = 0, y!: Int64 = 0, z!: Int64 = 0): This
设置页面转场时的平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Int64 | 否 | 0 | 横向的平移距离。 |
y | Int64 | 否 | 0 | 纵向的平移距离。 |
z | Int64 | 否 | 0 | 竖向的平移距离。 |
translate(Float64, Float64, Float64)
public func translate(x!: Float64 = 0.0, y!: Float64 = 0.0, z!: Float64 = 0.0): This
设置页面转场时的平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Float64 | 否 | 0.0 | 横向的平移距离。 |
y | Float64 | 否 | 0.0 | 纵向的平移距离。 |
z | Float64 | 否 | 0.0 | 竖向的平移距离。 |
translate(Length)
public func translate(value: Length): This
设置页面转场时的平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Length | 是 | - | 平移距离。 |
translate(CJResource)
public func translate(value: CJResource): This
设置页面转场时的平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | CJResource | 是 | - | 平移距离。 |
translate(Int64)
public func translate(value: Int64): This
设置页面转场时的平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Int64 | 是 | - | 平移距离。 |
translate(Float64)
public func translate(value: Float64): This
设置页面转场时的平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Float64 | 是 | - | 平移距离。 |
translateX(Length)
public func translateX(value: Length): This
设置页面转场时的横向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Length | 是 | - | 横向平移距离。 |
translateX(CJResource)
public func translateX(value: CJResource): This
设置页面转场时的横向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | CJResource | 是 | - | 横向平移距离。 |
translateX(Int64)
public func translateX(value: Int64): This
设置页面转场时的横向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Int64 | 是 | - | 横向平移距离。 |
translateX(Float64)
public func translateX(value: Float64): This
设置页面转场时的横向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Float64 | 是 | - | 横向平移距离。 |
translateY(Length)
public func translateY(value: Length): This
设置页面转场时的纵向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Length | 是 | - | 纵向平移距离。 |
translateY(CJResource)
public func translateY(value: CJResource): This
设置页面转场时的纵向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | CJResource | 是 | - | 纵向平移距离。 |
translateY(Int64)
public func translateY(value: Int64): This
设置页面转场时的纵向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Int64 | 是 | - | 纵向平移距离。 |
translateY(Float64)
public func translateY(value: Float64): This
设置页面转场时的纵向平移效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Float64 | 是 | - | 纵向平移距离。 |
scale(scaleValue: Float32)
public func scale(scaleValue: Float32): This
设置页面转场时的缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scaleValue | Float32 | 是 | - | 放大倍数(或缩小比例)。 |
scale(scaleValue: Int32)
public func scale(scaleValue: Int32): This
设置页面转场时的缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scaleValue | Int32 | 是 | - | 放大倍数(或缩小比例)。 |
scale(Float32, Float32, Float32, Length, Length)
public func scale(
x!: Float32 = 1.0,
y!: Float32 = 1.0,
z!: Float32 = 1.0,
centerX!: Length = 50.percent,
centerY!: Length = 50.percent
): This
设置页面转场时的缩放效果,为入场时起点和退场时终点的值。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Float32 | 否 | 1.0 | 横向放大倍数(或缩小比例)。 |
y | Float32 | 否 | 1.0 | 纵向放大倍数(或缩小比例)。 |
z | Float32 | 否 | 1.0 | 竖向放大倍数(或缩小比例)。 |
centerX | Length | 否 | 50.percent | 中心点坐标。 |
centerY | Length | 否 | 50.percent | 中心点坐标。 |
scale(Float32, Float32, Float32, CJResource, CJResource)
public func scale(
x!: Float32,
y!: Float32,
z!: Float32,
centerX!: CJResource,
centerY!: CJResource
): This
设置页面转场时的缩放效果,为入场时起点和退场时终点的值。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
x | Float32 | 是 | - | 横向放大倍数(或缩小比例)。 |
y | Float32 | 是 | - | 纵向放大倍数(或缩小比例)。 |
z | Float32 | 是 | - | 竖向放大倍数(或缩小比例)。 |
centerX | CJResource | 是 | - | 中心点坐标。 |
centerY | CJResource | 是 | - | 中心点坐标。 |
scaleX(Float32)
public func scaleX(scale: Float32): This
设置页面转场时的横向缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scale | Float32 | 是 | - | 放大倍数(或缩小比例)。 |
scaleX(Int32)
public func scaleX(scale: Int32): This
设置页面转场时的横向缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scale | Int32 | 是 | - | 放大倍数(或缩小比例)。 |
scaleY(Float32)
public func scaleY(scale: Float32): This
设置页面转场时的纵向缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scale | Float32 | 是 | - | 放大倍数(或缩小比例)。 |
scaleY(Int32)
public func scaleY(scale: Int32): This
设置页面转场时的纵向缩放效果。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
scale | Int32 | 是 | - | 放大倍数(或缩小比例)。 |
opacity(Float64)
public func opacity(value: Float64): This
设置入场的起点透明度值或者退场的终点透明度值。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Float64 | 是 | - | 入场的起点透明度值或者退场的终点透明度值。 |
opacity(Int64)
public func opacity(value: Int64): This
设置入场的起点透明度值或者退场的终点透明度值。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
value | Int64 | 是 | - | 入场的起点透明度值或者退场的终点透明度值。 |
PageTransitionOptions
init(RouteType, Int32, Curve, Int32)
public init(
`type`!: RouteType = RouteType.None,
duration!: Int32 = 1000,
curve!: Curve = Curve.Linear,
delay!: Int32 = 0
)
新建一个 PageTransitionOptions 类型对象。
说明
没有匹配时使用系统默认的页面转场效果(根据设备可能会有差异),如需禁用系统默认页面转场效果,可以指定duration为0。
参数名 | 参数类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
type | RouteType | 否 | RouteType.None | 页面转场效果生效的路由类型。 |
duration | Int32 | 否 | 1000 | 动画的时长。 |
curve | Curve | 否 | Curve.Linear | 动画曲线。 |
delay | Int32 | 否 | 0 | 动画延迟时长。 |
事件
onEnter((RouteType, Float64)->Unit)
public func onEnter(event: (RouteType, Float64)->Unit): This
参数名 | 参数类型 | 描述 |
---|---|---|
event | (RouteType, Float64)->Unit | 回调入参为当前入场动画的归一化进度[0 - 1]。- type:RouteType 跳转方法。- progress:Float64 当前进度。触发该事件的条件:逐帧回调,直到入场动画结束,progress从0变化到1。 |
onExit((RouteType, Float64)->Unit)
public func onExit(event: (RouteType, Float64)->Unit): This
参数名 | 参数类型 | 描述 |
---|---|---|
event | (RouteType, Float64)->Unit | 回调入参为当前退场动画的归一化进度[0 - 1]。- type:RouteType 跳转方法。- progress:Float64 当前进度。触发该事件的条件:逐帧回调,直到退场动画结束,progress从0变化到1。 |
枚举说明
RouteType
枚举值 | 描述 |
---|---|
Push | 重定向指定页面。从PageB回退到之前的页面PageA。对于PageB,指定RouteType为None或者Pop的PageTransitionExit组件样式生效,对于PageA,指定RouteType为None或者Pop的PageTransitionEnter组件样式生效。 |
Pop | 跳转到下一页面。PageA跳转到下一个新的界面PageB。对于PageA,指定RouteType为None或者Push的PageTransitionExit组件样式生效,对于PageB,指定RouteType为None或者Push的PageTransitionEnter组件样式生效。 |
None | 页面未重定向。如Push和Pop描述中RouteType为None的情形,即页面进场时PageTransitionEnter的转场效果生效;退场时PageTransitionExit的转场效果生效。 |
SlideEffect
枚举值 | 描述 |
---|---|
Left | 设置到入场时表示从左边滑入,出场时表示滑出到左边。 |
Right | 设置到入场时表示从右边滑入,出场时表示滑出到右边。 |
Top | 设置到入场时表示从上边滑入,出场时表示滑出到上边。 |
Bottom | 设置到入场时表示从下边滑入,出场时表示滑出到下边。 |
示例代码
import ohos.base.*
import ohos.component.Column
import ohos.component.Row
import ohos.component.Button
import ohos.component.Text
import ohos.component.CustomView
import ohos.component.CJEntry
import ohos.component.loadNativeView
import ohos.component.*
import ohos.router.*
import ohos.state_manage.SubscriberManager
import ohos.state_manage.ObservedProperty
import ohos.state_macro_manage.Entry
import ohos.state_macro_manage.Component
import ohos.state_macro_manage.State
import ohos.state_macro_manage.r
@Entry
@Component
class MyView {
@State var scale2: Float32 = 1.0
@State var opacity2: Float64 = 1.0
func build() {
Column() {
Image(@r(app.media.background)).width(100.percent).height(100.percent)
}
.width(100.percent)
.height(100.percent)
.scale(x: scale2, y: 1.0)
.opacity(this.opacity2)
.onClick { e =>
Router.push(url: "Page1")
}
}
protected func onTransition(): Unit {
PageTransitionEnter(PageTransitionOptions(duration: 1200, curve: Curve.Linear))
.onEnter { ty: RouteType, progress: Float64 =>
match (ty) {
case RouteType.Push | RouteType.Pop =>
scale2 = Float32(progress)
opacity2 = progress
case _ => ()
}
}
PageTransitionExit(PageTransitionOptions(duration: 1200, curve: Curve.Ease))
.onExit { ty: RouteType, progress: Float64 =>
match (ty) {
case RouteType.Push =>
this.scale2 = Float32(1.0 - progress)
this.opacity2 = 1.0 - progress
case _ => ()
}
}
}
}
// page1.cj
@Entry
@Component
class Page1 {
@State var scale1: Float32 = 1.0
@State var opacity1: Float64 = 1.0
func build() {
Column() {
Image(@r(app.media.background)).width(50.percent).height(50.percent)
}
.width(100.percent)
.height(100.percent)
.scale(x: scale1, y: 1.0)
.opacity(opacity1)
.onClick { e =>
Router.push(url: "MyView")
}
}
protected func onTransition(): Unit {
PageTransitionEnter(PageTransitionOptions(duration: 1200, curve: Curve.Linear))
.onEnter { ty: RouteType, progress: Float64 =>
match (ty) {
case RouteType.Push | RouteType.Pop =>
scale1 = Float32(progress)
opacity1 = progress
case _ => ()
}
}
PageTransitionExit(PageTransitionOptions(duration: 1200, curve: Curve.Ease))
.onExit { ty: RouteType, progress: Float64 =>
match (ty) {
case RouteType.Push =>
this.scale1 = Float32(1.0 - progress)
this.opacity1 = 1.0 - progress
case _ => ()
}
}
}
}
[图片上传失败...(image-af19c9-1735046595391)]