【问题标题】:CALayerInvalidGeometry when going from one view to another从一个视图转到另一个视图时的 CALayerInvalidGeometry
【发布时间】:2020-05-23 17:12:10
【问题描述】:

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

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
                        }

【问题讨论】:

    标签: swift swiftui swift5


    【解决方案1】:

    问题是自定义按钮没有关闭键盘,这在将下一个视图布尔值设置为 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
    }
    

    这为我解决了问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      相关资源
      最近更新 更多