【发布时间】:2021-09-18 10:47:30
【问题描述】:
我想添加一个形状以围绕其轴旋转并使用它来创建背景。为此,我创建了一个背景视图并决定在我的所有屏幕上使用该视图。
似乎当我在导航视图中添加背景视图时,它锚定在中心以外的其他位置。谁能告诉我如何在导航视图中实现预期结果?
但是,当我为元素提供旋转效果时,它在所有视图中都按预期工作,但包含导航视图的视图除外。
我无法在此处添加视频,但添加驱动器链接以更好地解释我的问题。
背景视图
背景视频链接(预期结果):Background View
struct BackgroundView: View {
@State private var rotateBlob : Bool = false
var body: some View {
GeometryReader { bounds in
ZStack {
Image("Inner Blob 1")
.rotationEffect(.degrees(rotateBlob ? 360 : 0),anchor: .center)
.animation(Animation.linear(duration: 3).repeatForever(autoreverses: false))
.onAppear(perform: {
self.rotateBlob = true
})
}
.frame(width: bounds.size.width)
}
}}
导航视图内的背景视图(意外结果): Background View Inside Navigation View
struct RotationBug: View {
var body: some View {
NavigationView{
VStack{
BackgroundView()
}
.navigationTitle("Profile")
}
}
}
【问题讨论】:
-
这是否回答了您的问题stackoverflow.com/a/64566746/12299030?
-
是的,有一个类似的问题,我必须将值作为绑定传递以跨导航视图解决它。
标签: ios swiftui swiftui-navigationview