我想旋转我的视图,以便它改变它的框架并在旋转时覆盖整个屏幕。我已经尝试了所有类型的旋转以及不同的锚点。这在 iOS 13 中运行良好,但在 iOS 14 中,视图和边距之间存在奇怪的差距。
struct ContentView: View {
@State private var isFullScreen = false
var body: some View {
NavigationView {
GeometryReader { geometry in
ZStack(alignment: .center) {
VStack(spacing: 0) {
HStack(alignment: .top)
{
Spacer(minLength: 0)
ZStack(alignment: Alignment(horizontal: .trailing, vertical: .center)) {
RoundedRectangle(cornerRadius: 0)
.foregroundColor(Color.yellow)
VStack {
Button(action: {
self.isFullScreen.toggle()
}, label: {
Text("FS")
})
}
}
.frame(width: self.isFullScreen ? geometry.size.height : geometry.size.width, height: self.isFullScreen ? geometry.size.width : geometry.size.height / 3)
.rotation3DEffect(
Angle(degrees: isFullScreen ? -90 : 0),
axis: (x: 0.0, y: 0, z: 1.0),
anchor: .bottom,
anchorZ: 0.0,
perspective: 1.0
)
}
}
}.background(Color.red)
.navigationBarHidden(self.isFullScreen)
.navigationBarTitle(self.isFullScreen ? "" : "Demo", displayMode: .inline)
}
}.navigationViewStyle(StackNavigationViewStyle())
}
}