- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在列表上使用匹配的几何效果,并且至少对于详细 View 的动画来说,它的工作方式与预期的一样。问题是从详细 View 返回列表单元格的动画似乎在列表后面。
我怎样才能让它正常工作,以便详细 View 缩小回列表单元格?这是我手机的代码:
struct Cell: View {
var exercise: Exercise
var index: Int
var namespace: Namespace.ID
var body: some View {
VStack {
Text(exercise.title)
.matchedGeometryEffect(id: exercise.id, in: namespace)
.font(.title)
.foregroundColor(.white)
.frame(maxWidth: .infinity, alignment: .leading)
.frame(height: 100)
}
.padding(.horizontal)
.padding(.top)
.padding(.bottom, 4)
.background(
RoundedRectangle(cornerRadius: 5, style: .continuous)
.matchedGeometryEffect(id: exercise.id + "background", in: namespace)
.background(Color.clear)
.foregroundColor(Color.gray)
)
.clipped()
}
}
这是列表本身:
struct ListView: View {
var testData: [Exercise]
var namespace: Namespace.ID
@Binding var tappedCellIndex: Int?
var body: some View {
ScrollView {
LazyVStack {
ForEach(testData.indices) { index in
Cell(exercise: testData[index], index: index, namespace: namespace)
.onTapGesture {
withAnimation(.spring(response: 0.6, dampingFraction: 0.8)) {
self.tappedCellIndex = index
}
}
}
}
}
}
}
这是内容 View :
struct ContentView: View {
let testData = [Exercise(title: "Hallo"), Exercise(title: "Bankdrücken"), Exercise(title: "Squats"), Exercise(title: "Seitheben"), Exercise(title: "Klimmzüge"), Exercise(title: "Bizepscurls"), Exercise(title: "Dips"), Exercise(title: "Aufroller"), Exercise(title: "Muscle"), Exercise(title: "Dragon Flies"), Exercise(title: "Hallo"), Exercise(title: "Bankdrücken"), Exercise(title: "Squats"), Exercise(title: "Seitheben"), Exercise(title: "Klimmzüge"), Exercise(title: "Bizepscurls"), Exercise(title: "Dips"), Exercise(title: "Aufroller"), Exercise(title: "Muscle"), Exercise(title: "Dragon Flies")]
@State var tappedCellIndex: Int? = nil
@Namespace var namespace
var body: some View {
ZStack {
VStack {
ListView(testData: testData, namespace: namespace, tappedCellIndex: $tappedCellIndex)
.opacity(tappedCellIndex == nil ? 1 : 0)
.transition(.scale(scale: 1))
}
if let tappedCellIndex = tappedCellIndex {
DetailView(exercise: testData[tappedCellIndex], selectedIndex: $tappedCellIndex, namespace: namespace)
.transition(.scale(scale: 1))
}
}
}
}
这是它应该动画返回的详细 View :
struct DetailView: View {
var exercise: Exercise
@Binding var selectedIndex: Int?
var namespace: Namespace.ID
var body: some View {
VStack(alignment: .leading) {
HStack {
Text(exercise.title)
.matchedGeometryEffect(id: exercise.id, in: namespace)
.font(.title)
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(Color.white)
.padding(.top, 12)
Spacer()
Button {
withAnimation(.spring(response: 0.6, dampingFraction: 0.8)) {
selectedIndex = nil
}
} label: {
Text("Klicke hier!")
}
}
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding()
.background(
RoundedRectangle(cornerRadius: 30, style: .continuous)
.matchedGeometryEffect(id: exercise.id + "background", in: namespace)
.foregroundColor(Color.gray)
)
}
}
最后这是模型:
struct Exercise: Identifiable, Hashable, Equatable {
var id = UUID().uuidString
var title: String
static func == (lhs: Exercise, rhs: Exercise) -> Bool {
return lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
对不起,代码太多了。我希望我添加了所有需要的内容。
顺便说一句:我还收到错误“在匹配的几何组中插入多个 View ”。我认为那是因为我在显示详细 View 时没有隐藏列表。我在 stackoverflow 上阅读了关于此的不同意见,在我看来,并不是在所有情况下都需要在显示另一个 View 时隐藏一个 View ,我也许可以忽略错误消息。
我也无法隐藏列表,因为重新加载会刷新列表,我会再次从列表顶部开始,因此向后动画也将不起作用。
如果有任何帮助,我将不胜感激
最佳答案
我肯定会建议显示一个空的占位符以防止“多个插入的 View ”。此外,.frame(maxWidth, maxHeight)
必须位于 .matchedGeometry
之前,因此 View 可以在动画中缩小或增大。
修改后的代码,查看注释:
struct Cell: View {
var exercise: Exercise
var index: Int
var namespace: Namespace.ID
var body: some View {
VStack {
Text(exercise.title)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) // moved + maxHeight!
.font(.title)
.foregroundColor(.white)
.matchedGeometryEffect(id: exercise.id, in: namespace)
}
.frame(height: 100) // moved
.padding(.horizontal)
.padding(.top)
.padding(.bottom, 4)
.background(
RoundedRectangle(cornerRadius: 5, style: .continuous)
.matchedGeometryEffect(id: exercise.id + "background", in: namespace)
.background(Color.clear)
.foregroundColor(Color.gray)
)
// .clipped()
}
}
struct ListView: View {
var testData: [Exercise]
var namespace: Namespace.ID
@Binding var tappedCellIndex: Int?
var body: some View {
ScrollView {
LazyVStack {
ForEach(testData.indices) { index in
// check if tapped
if index != tappedCellIndex {
Cell(exercise: testData[index], index: index, namespace: namespace)
.onTapGesture {
withAnimation(.spring(response: 0.6, dampingFraction: 0.8)) {
self.tappedCellIndex = index
}
}
} else { // display empty space
Color.clear
.frame(height: 100)
}
}
}
}
}
}
struct ContentView: View {
let testData = [Exercise(title: "Hallo"), Exercise(title: "Bankdrücken"), Exercise(title: "Squats"), Exercise(title: "Seitheben"), Exercise(title: "Klimmzüge"), Exercise(title: "Bizepscurls"), Exercise(title: "Dips"), Exercise(title: "Aufroller"), Exercise(title: "Muscle"), Exercise(title: "Dragon Flies"), Exercise(title: "Hallo"), Exercise(title: "Bankdrücken"), Exercise(title: "Squats"), Exercise(title: "Seitheben"), Exercise(title: "Klimmzüge"), Exercise(title: "Bizepscurls"), Exercise(title: "Dips"), Exercise(title: "Aufroller"), Exercise(title: "Muscle"), Exercise(title: "Dragon Flies")]
@State var tappedCellIndex: Int? = nil
@Namespace var namespace
var body: some View {
ZStack {
VStack {
ListView(testData: testData, namespace: namespace, tappedCellIndex: $tappedCellIndex)
.opacity(tappedCellIndex == nil ? 1 : 0)
// .transition(.scale(scale: 1))
}
if let tappedCellIndex = tappedCellIndex {
DetailView(exercise: testData[tappedCellIndex], selectedIndex: $tappedCellIndex, namespace: namespace)
// .transition(.scale(scale: 1))
}
}
}
}
struct DetailView: View {
var exercise: Exercise
@Binding var selectedIndex: Int?
var namespace: Namespace.ID
var body: some View {
VStack(alignment: .leading) {
HStack {
Text(exercise.title)
.frame(maxWidth: .infinity, alignment: .leading) // moved
.matchedGeometryEffect(id: exercise.id, in: namespace)
.font(.title)
.foregroundColor(Color.white)
.padding(.top, 12)
Spacer()
Button {
withAnimation(.spring(response: 0.6, dampingFraction: 0.8)) {
selectedIndex = nil
}
} label: {
Text("Klicke hier!")
}
}
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding()
.background(
RoundedRectangle(cornerRadius: 30, style: .continuous)
.matchedGeometryEffect(id: exercise.id + "background", in: namespace)
.foregroundColor(Color.gray)
)
}
}
struct Exercise: Identifiable, Hashable, Equatable {
var id = UUID().uuidString
var title: String
static func == (lhs: Exercise, rhs: Exercise) -> Bool {
return lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
关于ios - 匹配的几何效果向后动画似乎在 View 后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72922210/
谁能帮我解决这个问题?我有一个 Tomcat 和简单的 JSF 应用程序:https://github.com/gooamoko/jsfbilling/ .当我在 Tomcat 上运行应用程序时,它运
我有两个这样的域类,第一个是 Manager : package com.mnm class Manager { String name; static hasMany = [ pro
当我运行以下代码时,打印输出似乎不正确。 void thread_Calc(int *pos) { printf("recieved %d\n", *pos); sig = -1; man
这个问题在这里已经有了答案: How to access a local variable from a different function using pointers? (10 个答案) 关闭
我编写了一个程序,其中列表构建器方法返回 IEnumerable of string,其中包括大量字符串(100 万个项目),我将其存储在 List of string 中,然后它将所有项目附加到 中
我正在尝试编写一个 IRC 类型的聊天客户端,它具有可以连接到服务器的客户端。我试图让它在本地 atm 上工作(使用 FIFOS 而不是套接字)。 我遇到了以下我似乎无法解决的问题: 接受新的客户端连
我的一个 cronjobs 每天发送一封电子邮件 35 6 * * * cd $EZPUBLISHROOT && $PHP runcronjobs.php -q 2>&1 我停止使用 cron sud
我使用 WPF 打印路径来处理在我们的应用程序中创建的大型图表。整个图表由视觉效果组成。 所谓的“DesignerPaginator”对图表进行分页(非常简单)。 从这一点来说,我做了以下三件事: -
我尝试在更新之前跟踪系统应用程序并使用: public static boolean isSystemApplication(Context ctx, IContent content) {
我在这里附上了一个查询分析结果,https://explain.depesz.com/s/x9BN 这是查询 EXPLAIN ANALYZE SELECT branche
我正在做一个 CXF(spring) 项目 (HUB)。部署后,我可以看到肥皂和休息服务列表,我通过两个地址打开它。一种是使用本地主机,第二种是使用我电脑的 ip。所以我得到了这些输出。 使用本地主机
这是一个 AnyHashable 不支持枚举转换的简单案例。 enum testEnum: String { case Test } let myObject: AnyHashable = t
我的主要目标是比较存储在数据库和 XLSX 文件中的数据。 为此,我按以下方式创建了两个列表: private class ProductList { public string produc
我从 CMake 3.6 更新到任何最新版本 (3.12.0-rc2),现在我的一个程序无法编译。 奇怪的是,错误消息显示了标准库本身中的 undefined symbol 。这是错误消息: Unde
我希望将我的自定义对话框动画化为从特定点出现,但我无法为对话框设置动画。 该对话框是一个基本的 RelativeLayout,设置为 extends Dialog 类中的布局。 正如这里的一些答案所建
我已经在这个论坛上调查过很多类似的问题,但似乎没有一个能解决我的问题。 我会在底部列出我在这个论坛上看到的一些问题页面,但让我先谈谈我对这个问题的看法。 我正在使用 codeigniter v 2.x
我正在尝试在 RHEL 7 上启动一个 docker-compose 项目作为 systemd 服务。这是我的 systemd 脚本 (/etc/systemd/system/wp.service):
这个问题已经有答案了: "Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key",
我正在尝试在 RHEL 7 上启动一个 docker-compose 项目作为 systemd 服务。这是我的 systemd 脚本 (/etc/systemd/system/wp.service):
此问题出现在my last question here之后。我想将每个按钮聚焦和失去焦点背景设置为主菜单(ContentPane 即 JPanel)下方的背景颜色,因此按钮看起来像选项卡。它在不同的环
我是一名优秀的程序员,十分优秀!