swiftUI3.0制作行星App
核心源码
//
// ContentView.swift
// LJPlanets
//
// Created by lujun on 2022/1/24.
//
import SwiftUI
//导入场景Kit 导入场景框架
import SceneKit
struct ContentView: View {
@State var currentIndex = 0
var body: some View {
VStack{
ZStack{
HStack{
Button {
withAnimation {
if currentIndex > 0 {
currentIndex -= 1
}
}
} label: {
Image(systemName: "chevron.left")
.font(.system(size: 35))
.opacity(currentIndex == 0 ? 0.3 : 1)
}
.disabled(currentIndex == 0 ? true : false)
Spacer()
Button {
withAnimation {
if currentIndex < planets.count - 1 {
currentIndex += 1
}
}
} label: {
Image(systemName: "chevron.right")
.font(.system(size: 35))
.opacity(currentIndex == (planets.count - 1) ? 0.3 : 1)
}
.disabled(currentIndex == (planets.count - 1) ? true : false)
}
Text(planets[currentIndex].name)
.font(.system(size: 45) .bold())
}
.foregroundColor(.black)
.padding(.horizontal)
.padding(.vertical,30)
SceneView(scene: SCNScene(named: planets[currentIndex].filename),options: [.autoenablesDefaultLighting,.allowsCameraControl])
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.width)
//关于行星
VStack(alignment:.leading,spacing: 15){
Text("关于")
.font(.title.bold())
+ Text(planets[currentIndex].name)
.font(.title.bold())
ScrollView(.vertical, showsIndicators: false) {
Text(planets[currentIndex].details)
}
}
.padding()
Spacer()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术