希望有人知道这个动画问题的解决方案,因为我找不到让它工作的方法!
我在 ScrollView 中的 LazyVStack 中使用 ForEach。我在滚动视图上有一个 .searchable 修饰符。当我输入/取消搜索字段时,导航栏和搜索字段会向上/向下动画,但我的滚动视图会跳转而没有动画。
如果我在 .searchable 之后添加 .animation(.easeInOut) ,它会正确显示动画。然而,有两个问题,它在 iOS 15.0 中已被弃用,并且当列表项出现和过滤时,它会以疯狂的方式为列表项设置动画。
使用列表时,它也可以工作,但无法按照我需要的方式进行自定义。此问题存在于模拟器、预览版和设备中。
有谁知道我如何才能在不使用列表的情况下正确地制作动画(列表不具有列表项所需的可定制性)?
感谢您的帮助!
我正在做的重现问题的简化版本:
import SwiftUI
struct ContentView: View {
@State var searchText: String = ""
var body: some View {
NavigationView {
ScrollView(.vertical) {
CustomListView()
}
.navigationTitle("Misbehaving ScrollView")
.searchable(text: $searchText, placement: .automatic)
// This .animation() will fix the issue but create many more...
// .animation(.easeInOut)
}
}
}
struct CustomListView: View {
@State private var listItems = ["Item 0", "Item 1", "Item …
Run Code Online (Sandbox Code Playgroud) 因此,在按下按钮时,我正在创建 splitLat: [Double] 从一个名为 splitLatitude 的投掷函数,该函数采用 currentLocation: CLLocationCoordinate2D?。然后我想使用 splitLat 作为标签(它也将用于其他事情,但这只是一个例子)
@IBAction func ButtonPress() {
let splitLat = try self.splitLatitude(self.currentLocation)
LatSplitLabel.text = "\(splitLat)"
}
Run Code Online (Sandbox Code Playgroud)
这得到一个错误“从这里抛出的错误没有被处理”
我通过把它放在一个 do catch 块中来解决这个问题
do{
let splitLat = try self.splitLatitude(self.currentLocation)
} catch {
print("error") //Example - Fix
}
Run Code Online (Sandbox Code Playgroud)
但是当我稍后尝试在 splitLat 上设置标签时是“未解析的标识符”
Swift 和编程的新手,我是否遗漏了一些基本的东西/我有误解吗?有没有办法可以在 do 语句之外使用 do {} 语句中的常量。尝试返回,但这是为函数保留的。
真的很感谢任何帮助
谢谢