[英]SwiftUI : Input Field Keyboard animation causing other views in tab view to animate
Interaction with an input field in a view inside my TabView, is causing my other views to animate weirdly when they appear.与我的 TabView 内部视图中的输入字段的交互导致我的其他视图在出现时出现奇怪的动画。 In addition, the nav bar doesn't hide as it should.
此外,导航栏没有按应有的方式隐藏。
I've established it is an input field + TabView problem because:我已经确定这是一个输入字段 + TabView 问题,因为:
I've looked into a few solutions but had no luck: Is there a way to override the keyboard animation?我研究了一些解决方案,但没有运气:有没有办法覆盖键盘 animation? Is there a way to force the tab view views to "appear" when the tab view loads?
有没有办法在标签视图加载时强制标签视图视图“出现”? Is there a way to stop other TabView sub views being impacted by changes in other TabView views
有没有办法阻止其他 TabView 子视图受到其他 TabView 视图更改的影响
Tab iew Code选项卡代码
TabView (){
ViewA()
.tabItem {
Image("viewa").renderingMode(.template)
Text("viewa")
}
ViewB()
.tabItem {
Image("viewb").renderingMode(.template)
Text("viewb")
}
ViewC()
.tabItem {
Image("viewc").renderingMode(.template)
Text("viewc")
}
ViewD()
.tabItem {
Image("viewd").renderingMode(.template)
Text("viewd")
}
}
In the tab views child views, animation is applied to a VStack containing my items like so.在选项卡视图子视图中,animation 应用于包含我的项目的 VStack,如下所示。
VStack{
items...
}.animation(.easeInOut)
This code is used to hide the nav:此代码用于隐藏导航:
.background(NavigationConfigurator { nav in
nav.hidesBarsOnSwipe = true
})
Expected behaviour:预期行为:
Behaviour when interacting with an input field:与输入字段交互时的行为:
It appears this is an ongoing bug with TabView and the keyboard.看来这是 TabView 和键盘的持续错误。 The temporary fix until this is resolved is converting the VStacks to LazyVStacks so that the views do not load until necessary.
在解决此问题之前的临时修复是将 VStacks 转换为 LazyVStacks,以便在必要时不会加载视图。
See: OnAppear calls unexpectedly when Keyboard Appears in SwiftUI请参阅: 在 SwiftUI 中出现键盘时意外调用 OnAppear
There is a modifier you can use to fix this that is supported.有一个修饰符可用于修复此受支持的问题。 try using this:
尝试使用这个:
.ignoresSafeArea(.keyboard)
this will keep anything from moving out of the keyboard's safe area while it is moving.这将防止任何东西在移动时移出键盘的安全区域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.