如何解决如何修改自定义ButtonStyle动画
您可以通过实现自己的Button
并根据ButtonStyle
状态修改label
来使用SwiftUI修改isPressed
的高亮/按下状态。
在iOS 13中,此动画在触地和触地时均具有动画效果。在iOS 14 Beta中,它不会在按下时动画,而仅在向上动画。我想启用触地动画。该怎么办?
struct CustomButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.5 : 1)
}
}
struct CustomButton: View {
var body: some View {
Button(action: {}) {
RoundedRectangle(cornerRadius: 10)
.frame(width: 100,height: 100)
.foregroundColor(.pink)
}
.buttonStyle(CustomButtonStyle())
}
}
解决方法
只需以按钮样式npm install --save-dev node-sass sass-loader
定义一个明确的动画。
例如,您可以在make body
下添加.animation(.easeOut)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。