[英]SwiftUI unexpected animation on appear
I have created custom TabBar
.我创建了自定义TabBar
。
Everything works fine, until I embed one of the tab's view in to NavigationView
, than result - appearance animation of a View
from very top left corner to right corner (screen with text and yellow color):一切正常,直到我将选项卡的一个视图嵌入到NavigationView
中,结果 - 从左上角到右上角的View
的外观 animation(带有文本和黄色的屏幕):
How tabBar is done: basically View
's body created using GeometryReader
VStack
/ Zstack
: tabBar 是如何完成的:基本上View
的主体是使用GeometryReader
VStack
/ Zstack
创建的:
var body: some View {
GeometryReader { geometry in
let height = geometry.size.height
let width = geometry.size.width
let bottomSafeAreaInset = geometry.safeAreaInsets.bottom
let topSafeAreaInset = geometry.safeAreaInsets.top
let verticalSafeAreaInset = bottomSafeAreaInset + topSafeAreaInset
VStack(spacing: 0) {
// content
mainContentBody
.frame(width: width, height: height - heightOfTabBar)
.zIndex(0)
// some calculation ...
// tabBar
Spacer(minLength: 0)
BottomBar(barButtonItems: buttons)
.frame(width: width, height: tabBarHeightWithOffset)
.background(Color.gray)
.offset(y: isMenuShown ? tabBarHeightWithOffset : 0)
.edgesIgnoringSafeArea(.all)
.opacity(isMenuShown ? 0 : 1)
.tabContainerAnimation() // simple wrapper for animation with duration
//... other view in ZStack
// button
ZStack {
overlayButton
}
.offset(y: -initialButtonOffset + additionalOffsetForButton)
.tabContainerAnimation(delay: 0.25)
}
}
}
And Code for view on tab1:在 tab1 上查看代码:
struct Tab1View: View {
var body: some View {
NavigationView {
VStack {
Text("sdsd")
Color.orange
}
}
}
}
If I remove NavigationView
this effect is removed also.如果我删除NavigationView
这个效果也会被删除。 So my question is - why do i have this unexpected animation?所以我的问题是 - 为什么我有这个意想不到的 animation? what done wrong?做错了什么?
Here is fix (tested with Xcode 12.1 / iOS 14.1)这是修复(使用 Xcode 12.1 / iOS 14.1 测试)
struct Tab1View: View {
var body: some View {
GeometryReader { g in
NavigationView {
VStack {
Text("sdsd")
Color.orange
}
}
.animation(.none) // << this one !!
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.