ios - 按下时如何为所有选项卡图标(不仅仅是一个)设置动画?
问题描述
我正在使用 if 语句,但它仅适用于通知铃图标,如何将相同的效果应用于其他图标?我应该使用 switch 语句吗?
if selection == index {
Color(.label)
.frame(height: 2)
.offset(y: -8)
.matchedGeometryEffect(id: "currentTab", in: currentTab)
}
if tabs[selection].label == "Notifications" && tabs[index].label == "Notifications" {
Image(systemName: tabs[index].image)
.frame(height: 20)
.rotationEffect(.degrees(25))
} else {
Image(systemName: tabs[index].image)
.frame(height: 20)
.rotationEffect(.degrees(0))
}
Text(tabs[index].label) .font(.caption2)
.fixedSize()
.foregroundColor(.blue)
}
.fixedSize(horizontal: false, vertical: true)
.frame(width: geometry.size.width / 2, height: 44, alignment: .bottom).padding(.horizontal).foregroundColor(selection == index ? Color(.label) : .secondary )
.onTapGesture{
withAnimation{selection = index}
}
}
}
}.frame(height: 44, alignment: .bottom)
}
}
解决方案
推荐阅读
- android - 在 Firebase Analytics 中,有什么方法可以知道“直接”的来源
- bootstrap-4 - 为什么要自动选择当前日期时间?如何停止自动选择当前数据时间?我怎样才能得到只有一年?
- java - Groovy StreamingTemplateEngine IOException:不支持标记()
- ios - 在 UITextfield 中定位“清除按钮”
- powerbi - Power BI - 从数据集中获取图表
- c++ - 是否可以在 C++ 标准库中实现 always_false?
- reactjs - data-reactroot 是否与 React 中的水合物函数相关?
- javascript - 如何在 React Date Picker 中显示该国家/地区的日期和时间?
- javascript - 评估返回的 JSON 响应中元素的排序顺序,该元素是时间戳
- javascript - 必须在 Angular 中以形式提供名称的值