WWDC23
25m
https://developer.apple.com/videos/play/wwdc2023/10109/

Button, Button with tooltip, Toggle, TabView, Slider, Stepper, Alert 가 있다고 하네요.

Button("Of course") { ... }

Toggle(isOn: $favorite) {
Label("Favorite", systemImage: "star")
}


TabView {
DogsTab()
.tabItem { ... }
CatsTab()
.tabItem { ... }
BirdsTab()
.tabItem { ... }
}
@main
struct WorldApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Window
Volumes
Full Spaces

이 Scene들을 믹스하고 매치시켜 목적에 맞게 함께 사용할 수 있어요.

@main
struct WorldApp: App {
var body: some Scene {
WindowGroup("Hello, world") {
TabView {
Modules()
.tabItem { ... }
FunFactsTab()
.tabItem { ... }
}
}
}
}
TabView에는 .ornament 모디파이어를 사용할 수 있어요.
VStack(alignment: .leading) {
Text("Stats")
.font(.title)
StatsGrid(stats: stats)
.padding()
.background(.regularMaterial,
in: .rect(cornerRadius: 12))
}

Button(action: { ... }) {
VStack(alignment: .leading) {
Text(fact.title)
.font(.title2)
.lineLimit(2)
Text(fact.details)
.font(.body)
.lineLimit(4)
Text("Learn more")
.font(.caption)
.foregroundStyle(.secondary)
}
}
.buttonStyle(.funFact)


struct FunFactButtonStyle: ButtonStyle {
func makeBody(
configuration: Configuration
) -> some View {
configuration.label
.padding()
.background(.regularMaterial,
in: .rect(cornerRadius: 12))
.hoverEffect()
}
}
windowStyle을 .volumetric으로 바꿀 수 있어요.@main
struct WorldApp: App {
var body: some Scene {
WindowGroup {
Globe()
}
.windowStyle(.volumetric)
.defaultSize(width: 600, height: 600, depth: 600)
}
}
import SwiftUI
import RealityKit
struct Globe: View {
var body: some View {
Model3D(named: "Earth")
}
}
Model3D를 사용하여 간단하게 지구를 띄어볼 수 있어요.
import SwiftUI
import RealityKit
struct Globe: View {
var body: some View {
ZStack(alignment: .bottom) {
Model3D(named: "Earth")
.rotation3DEffect(rotation, axis: .y)
.onTapGesture {
withAnimation(.bouncy) {
rotation.degrees += randomRotation()
}
}
.padding3D(.front, 200)
GlobeControls()
.glassBackgroundEffect(in: .capsule)
}
}
}
ZStack 을 사용하여 모델 아래에 컨트롤을 추가해줄 수 있답니다.onTapGesture와 withAnimation을 사용하여 손으로 rotation 할 수도 있어요.
ReallityView { content in
if let earth = try? await
ModelEntity(name: "Earth")
{
earth.addImageBasedLigthing()
content.add(earth)
}
}
@State private var pinLocation: GlobeLocation?
RealityView {
...
} update: {
...
if let pin = attachments.entity(for: "pin") {
content.add(pin)
placePin(pin)
}
} attachments: {
if let pinLocation {
GlobePin(pinLocation: pinLocation)
.tag("pin")
}
}
.gesture(
SpatialTapGesture()
.targetedToAnyEntity()
.onEnded { value in
pinLocation = lookUpLocation(at: value)
}
)

@main
struct WorldApp: App {
var body: some Scene {
...
ImmersiveSpace(id: "solar-system") {
SolarSystem()
}
}
}
@Environment(\.openImmersiveSpace)
private var openImmersiveSpace
Button("View Outer Space") {
openImmersiveSpace(id: "solar-system")
}

@main
struct WorldApp: App {
@State private var selectedStyle: ImmersiveStyle = .full
var body: some Scene {
...
ImmersiveSpace(id: "solar-system") {
SolarSystem()
}
.immersiveStyle(
selection: $selectedStyle,
in: .full)
}
}
struct Starfield: View {
var body: some View {
RealityView { content in
let starfield = await loadStarfield()
content.add(starfield)
}
}
}
struct SolarSystem: View {
var body: some View {
Earth()
Sun()
Starfield()
}
}
