从一个视图转到另一个视图时的 CALayerInvalidGeometry

CALayerInvalidGeometry when going from one view to another

在一个视图中编辑值然后转到另一个视图(使用自定义按钮和导航链接)后,我收到以下错误:

Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan].

我的自定义按钮的代码是:

                    NavigationLink(destination: TripNotesEvalView(currentTrip: self.currentTrip), isActive: self.$goToNextView, label: { EmptyView() })
                        ZStack {
                            Image("btn-shape").resizable().frame(width: 60, height: 70).colorMultiply(self.btnThreeData.color)
                        }.onTapGesture {
                            self.goToNextView = true
                        }

问题是自定义按钮没有关闭键盘,这是在将下一个视图布尔值设置为 true 之前关闭键盘后导致问题的问题已解决:

关闭键盘:

extension UIApplication {
    func endEditing() {
        sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
    }
}

在我将布尔值设置为 true 之前在我的导航按钮中实现了这个方法:

NavigationLink(destination: TripNotesEvalView(currentTrip: self.currentTrip), isActive: self.$goToNextView, label: { EmptyView() })
ZStack {
    Image("btn-shape").resizable().frame(width: 60, height: 70).colorMultiply(self.btnThreeData.color)
}.onTapGesture {
    UIApplication.shared.endEditing()
    self.goToNextView = true
}

这解决了我的问题!