HarmonyOS 两个叠加形状组件做切换动画,如何实现绕中心旋转切换?(API12+)
将方形rect改为圆形,修改了borderRadius,并修改其大小、增加旋转。整体使用动画animation动画过渡。过渡效果与预期不一致。
预期结果:中心点不变进行旋转、大小、方形变圆形的动画过渡。
页面代码:
import { matrix4 } from '@kit.ArkUI';
@Entry
@Component
export default struct Riders {
@State opacityValue: number = 1
@State recording: boolean = false
build() {
Column() {
Button() {
Stack({ alignContent: Alignment.Center }) {
// 外环(动态颜色)
Circle()
.width(40)
.height(40)
.stroke(this.recording ? Color.Red : '#6964FF')
.strokeWidth(1.5)
.fill(Color.Transparent)
// 内部形(动态切换)
Rect()
.width(this.recording ? 18 : 28)
.height(this.recording ? 18 : 28)
.radius(this.recording ? 6 : 14)
.fill(this.recording ? Color.Red : '#6964FF')
.opacity(this.opacityValue)
.rotate({
angle: this.recording ? 90 : 0,
centerX: (this.recording ? 18 : 28) / 2,
centerY: (this.recording ? 18 : 28) / 2
})// 旋转角度
.animation({
duration: 500,
curve: Curve.EaseOut,
})
}
.width('100%')
.height('100%')
}
.width(50)
.height(50)
.backgroundColor(Color.Transparent)
.onClick(() => {
try {
this.recording = !this.recording
} catch (e) {
console.error(JSON.stringify(e), "createFloatWindowERROR")
}
})
}
.width('100%')
.height('100%')
.backgroundColor(Color.Black)
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Center)
}
}
1
浏览48 发布于2026-01-05 09:31未知归属地
全部评论
最多点赞
最新发布
最早发布
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要提问题
了解社区公约,与您携手共创和谐专业的开发者社区。





































苏公安网备 32011402010933号