我有一些代码可以在 iOS 14 中运行,但在 15 中,xe2x80x99 就不太行了。下图所示的单元格可以有一行或两行标题。在 iOS 14(右侧)中,Spacer()标题和列表计数文本之间的元素按预期展开,以便单元格的高度相同。在 iOS 15 中,情况并非如此,单元格会缩小,并在其行中居中(请参阅 \xe2\x80\x9cA-Train\xe2\x80\x9d 项)。
单元格的代码如下所示:
\nZStack\n{\n Color.white\n .cornerRadius(8)\n \n VStack(alignment: .leading, spacing: 0)\n {\n // Listing Image\xe2\x80\xa6\n \n GeometryReader\n { geom in\n KFImage(self.imageURL)\n .cancelOnDisappear(true)\n .placeholder {\n Image("product-placeholder")\n .resizable()\n .aspectRatio(contentMode: .fit)\n .frame(width: geom.size.width, height: geom.size.width)\n }\n .resizable()\n .aspectRatio(contentMode: .fill)\n .frame(width: geom.size.width, height: geom.size.width)\n .cornerRadius(4)\n .clipped()\n }\n .aspectRatio(contentMode: .fit)\n .padding(.bottom, 12)\n \n // Title\xe2\x80\xa6\n \n Text("\\(self.title)")\n .font(.custom("Poppins", size: 14.0).weight(.semibold))\n .multilineTextAlignment(.leading)\n .lineLimit(2)\n \n Spacer(minLength: 0) // Not expanding in iOS 15\n \n // Listing Count\xe2\x80\xa6\n \n if let listingCount = self.listingCount\n {\n Text("\\(listingCount) listings")\n .font(.custom("Inter", size: 12.0).weight(.medium))\n .foregroundColor(.secondaryText)\n .padding(.vertical, 8)\n }\n \n // Price\xe2\x80\xa6\n \n if let price = self.price\n {\n Text("\\(Self.priceFormatter.string(from: price as NSNumber)!)")\n .font(.custom("Inter", size: 14.0).weight(.semibold))\n }\n }\n .padding(12)\n}\nRun Code Online (Sandbox Code Playgroud)\n的列LazyVGrid是Array(repeating: .init(.flexible(), spacing: 20.0), count: 2)。
我无法判断 iOS 14 或 15 是否存在该错误。
\n小智 1
我在这里遇到完全相同的问题。一种可能性是解决它,至少如果您使用的是LazyVGridor VGrid。这可以通过将网格项与顶部对齐来完成。
Array(repeating: .init(.flexible(), spacing: 20.0), count: 2, alignment: .top)
Run Code Online (Sandbox Code Playgroud)
我知道这并不能完全解决问题,但它会将它们对齐在顶部,而不是居中。
| 归档时间: |
|
| 查看次数: |
1425 次 |
| 最近记录: |