在一个视图中编辑一个值然后转到另一个视图(使用自定义按钮和导航链接)后,出现以下错误:
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
}
答案 0 :(得分:0)
问题是自定义按钮无法关闭键盘,这在关闭键盘之后才将问题设置为下一个视图布尔值设置为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
}
这为我解决了问题!