您好,我正在为iPhone和iPad设计一个应用程序,因此我有条件检测屏幕尺寸.regular或.compact,然后在iPhone或.compact视图上显示iPad导航视图或tabview。 导入SwiftUI
struct NavigationViewForiPhone : View{
var body: some View{
TabView{
Text("Hi im on iphone or landscape on iPhone no plus")
.tabItem {
Image(systemName: "house.fill")
Text("Inicio")
}
Text("Hi im on iphone or landscape on iphone plus")
.tabItem {
Image(systemName: "house.fill")
Text("Second")
}
}
.background(Color.blue)
.navigationBarTitle("iPhone View")
}
}
struct NavigationViewForiPad : View{
var body: some View{
NavigationView{
List{
NavigationLink(destination: Text("Text hi")){
HStack{
Text("hi im a menu")
}
}
NavigationLink(destination: Text("Text hi")){
HStack{
Text("hi im a menu")
}
}
NavigationLink(destination: Text("Text hi")){
HStack{
Text("hi im a menu")
}
}
NavigationLink(destination: Text("Text hi")){
HStack{
Text("hi im a menu")
}
}
.navigationBarTitle("iPad View")
}
VStack{
Text("Hi im on ipad")
Text("Hi im on iPad or iPhone plus")
Text("Hi im on ipad")
}
.navigationViewStyle(DoubleColumnNavigationViewStyle())
}
.background(Color.red)
}
}
struct ContentView: View {
// MARK: - Detectar el tamaño de la pantalla
@Environment(\.horizontalSizeClass) var sizeClass
var body: some View{
Group{
// MARK: - Mostrar navegacion con pestañas en iPhone
if self.sizeClass == .compact
{
withAnimation(.easeInOut(duration: 1) ){
return NavigationViewForiPhone()
}
}
else
{
withAnimation(.easeInOut(duration: 1) ){
return NavigationViewForiPad()
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
所以问题是当在iPhone(加上大小和最大大小)上更改为横向或纵向时,视图的更改不平滑,我尝试了很多方法来为过渡设置动画,但我找不到办法。 / p>
有什么想法或建议吗?