swift - 摆脱按钮的标准 onTouch 动画
问题描述
当我在 SwiftUI 中实现一个 Button 时,当你点击它时,这个 Button 总是有一个标准的动画。轻微的不透明动画。有没有办法摆脱那个动画?这是一个简单的例子。
这是一个小视频-> https://imgur.com/ClWd7YH
import SwiftUI
struct ContentView: View {
var body: some View {
VStack{
Button(action: {
// do somethinh
}) {
VStack{
ZStack{
Circle()
.fill(Color.white)
.frame(width: 45, height: 45, alignment: .center)
Image(systemName: "xmark.circle")
.foregroundColor(Color.black)
.font(Font.system(size: 18, weight: .thin))
.padding(6)
}
Text("Press")
.foregroundColor( Color.white)
}.frame(width: 300, height: 300, alignment: .center)
}
}.background(Color.green)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
解决方案
您可以定义自己的ButtonStyle
将覆盖默认动画:
public struct ButtonWithoutAnimation: ButtonStyle {
public func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
}
}
现在只需在 上设置样式Button
:
Button(action: { .. } {
..
}.buttonStyle(ButtonWithoutAnimation())
推荐阅读
- python - 使用 pyodbc 和 SQL Server 一般网络错误更新语句
- solr - Sitecore 8.2 更新 5 Ninject Solr 支持包问题
- php - Php SoapClient 在第一次连接时很慢
- r - 在具有条件的矩阵中查找第 n 个百分位数
- java - 请求未异步处理
- r - 将复选框矩阵转换为列名的边缘列表
- reactjs - 从 Spring Boot 控制器获取反应下拉列表中的用户列表
- android - 访问 mObservables 时对 RecyclerView 适配器进行单元测试会引发 NullPointerException
- r - source():错误:替换的长度为零
- excel - 引用具有不同文件名的工作簿