参考demo://Tabs: import AnimateToExample from './Page' @Entry @Component struct TabsExample { @State fontColor: string = '#182431' @State selectedFontColor: string = '#007DFF' @State currentIndex: number = 0 private controller: TabsController = new TabsController() @State index:number = 0 @Builder tabBuilder(index: number, name: string) { Column() { Text(name) .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor) .fontSize(16) .fontWeight(this.currentIndex === index ? 500 : 400) .lineHeight(22) .margin({ top: 17, bottom: 7 }) }.width('100%').backgroundColor(Color.Green) .pixelRound({ start:PixelRoundCalcPolicy.FORCE_CEIL, end:PixelRoundCalcPolicy.FORCE_CEIL, top:PixelRoundCalcPolicy.FORCE_CEIL, bottom:PixelRoundCalcPolicy.FORCE_CEIL }).onAreaChange((oldValue: Area, newValue: Area) => { console.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`) }) } build() { Column() { Tabs({ barPosition: BarPosition.Start, index: this.currentIndex, controller: this.controller }) { TabContent() { AnimateToExample() }.tabBar(this.tabBuilder(0, 'index')).backgroundColor(Color.Red) TabContent() { }.tabBar(this.tabBuilder(1, 'detail')) } .vertical(false) .barMode(BarMode.Fixed) .barWidth(360) .barHeight(56) .animationDuration(400) .onChange((index: number) => { this.currentIndex = index }) .width(360) .height(296) .margin({ top: 52 }) .backgroundColor('#F1F3F5') .onTabBarClick((index) =>{ this.index = index }) }.width('100%') } } //page: @Entry @Component export default struct AnimateToExample { @State widthSize: number = 250 @State heightSize: number = 100 @State rotateAngle: number = 0 private flag: boolean = true @State num :number = -1 build() { Column() { Button('change size') .width(this.widthSize) .height(this.heightSize) .margin(30) .onClick(() => { if (this.flag) { animateTo({ duration: 2000, curve: Curve.EaseOut, iterations: 3, playMode: PlayMode.Normal, onFinish: () => { console.info('play end') } }, () => { this.widthSize = 150 this.heightSize = 60 }) } else { animateTo({}, () => { this.widthSize = 250 this.heightSize = 100 }) } this.flag = !this.flag }) Button('change rotate angle') .margin(50) .rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle }) .onClick(() => { animateTo({ duration: 1200, curve: Curve.Friction, delay: 500, iterations: this.num, // 设置-1表示动画无限循环 playMode: PlayMode.Alternate, onFinish: () => { console.info('play end') }, expectedFrameRateRange: { min: 10, max: 120, expected: 60, } }, () => { this.rotateAngle = 90 }) }) Button("click").onClick(() => { this.num = 0 }) }.width('100%').margin({ top: 5 }) } }
参考demo: