Tüm Yazılar
KategorivisionOS
Okuma Süresi
23 dk
Yayın Tarihi
...
Kelime Sayısı
1.454kelime

Kahveni hazırla - bu içerikli bir makale!

Apple Vision Pro için uygulama geliştirme. Windows, volumes, immersive spaces, RealityKit entegrasyonu ve spatial interaction patterns.

visionOS Development: Spatial Computing ile Geleceği Kodla

2 Şubat 2024'te Apple Vision Pro satışa çıktığında, spatial computing artık bilim kurgu değil gerçek oldu. Ve sen, bu yeni platformda uygulama geliştiren ilk nesil geliştiricilerden biri olabilirsin. visionOS, SwiftUI bilgini doğrudan kullanmana olanak tanıyor - zaten bildiğin dili konuşuyor.

İçindekiler

  1. visionOS Nedir?
  2. Uygulama Modelleri: Window, Volume, Space
  3. SwiftUI + visionOS: İlk Uygulamanız
  4. 3D Content: RealityKit ve RealityView
  5. Spatial Interaction: Göz, El, Ses
  6. Immersive Spaces
  7. SharePlay ve Persona
  8. Existing App'leri visionOS'a Taşıma
  9. Production Best Practices

visionOS Nedir? {#visionos-nedir}

visionOS, Apple Vision Pro'nun işletim sistemi. SwiftUI, RealityKit ve ARKit üzerine kurulu. Üç boyutlu, spatial (mekansal) uygulamalar geliştirmeni sağlıyor.

Platform
Input
Display
SDK
iOS
Touch
2D Ekran
UIKit/SwiftUI
macOS
Mouse/Trackpad
2D Ekran
AppKit/SwiftUI
visionOS
**Göz + El + Ses**
**3D Mekan**
SwiftUI + RealityKit

Dış Kaynaklar:


Uygulama Modelleri {#uygulama-modelleri}

visionOS'ta üç uygulama modeli var:

1. Window - 2D İçerik (Tanıdık)

swift
1@main
2struct MyVisionApp: App {
3 var body: some Scene {
4 // Standart 2D pencere - iOS uygulamanla neredeyse aynı!
5 WindowGroup {
6 ContentView()
7 }
8 }
9}

2. Volume - 3D İçerik (Yeni!)

swift
1@main
2struct My3DApp: App {
3 var body: some Scene {
4 WindowGroup {
5 ContentView()
6 }
7 .windowStyle(.volumetric) // 3D hacim!
8 .defaultSize(width: 0.5, height: 0.5, depth: 0.5, in: .meters)
9 }
10}

3. Immersive Space - Tam Mekan (Devrimsel!)

swift
1@main
2struct ImmersiveApp: App {
3 var body: some Scene {
4 WindowGroup {
5 ContentView()
6 }
7 
8 ImmersiveSpace(id: "solarSystem") {
9 SolarSystemView()
10 }
11 .immersionStyle(selection: .constant(.mixed), in: .mixed, .full)
12 }
13}

SwiftUI + visionOS {#ilk-uygulama}

swift
1struct ContentView: View {
2 @State private var showImmersive = false
3 @Environment(\.openImmersiveSpace) var openImmersiveSpace
4 @Environment(\.dismissImmersiveSpace) var dismissImmersiveSpace
5 
6 var body: some View {
7 NavigationStack {
8 VStack(spacing: 20) {
9 Text("Spatial Computing'e Hoş Geldin!")
10 .font(.extraLargeTitle) // visionOS'a özel font
11 
12 // 3D model doğrudan SwiftUI'da
13 Model3D(named: "Globe") { model in
14 model
15 .resizable()
16 .scaledToFit()
17 } placeholder: {
18 ProgressView()
19 }
20 .frame(width: 300, height: 300)
21 
22 // Ornament - pencere kenarına yapışan UI
23 Button("Immersive Space Aç") {
24 Task {
25 await openImmersiveSpace(id: "solarSystem")
26 showImmersive = true
27 }
28 }
29 }
30 .padding(50)
31 .ornament(attachmentAnchor: .scene(.bottom)) {
32 HStack {
33 Button("Info") { }
34 Button("Ayarlar") { }
35 }
36 .padding()
37 .glassBackgroundEffect() // visionOS cam efekti
38 }
39 }
40 }
41}

RealityKit ve RealityView {#realitykit}

swift
1struct SolarSystemView: View {
2 var body: some View {
3 RealityView { content in
4 // 3D sahne oluştur
5 let earth = try? await Entity(named: "Earth", in: realityKitContentBundle)
6 
7 if let earth {
8 earth.position = [0, 1.5, -2] // 2 metre önde
9 earth.scale = [0.3, 0.3, 0.3]
10 
11 // Sürekli dönme animasyonu
12 let rotation = FromToByAnimation<Transform>(
13 from: earth.transform,
14 to: Transform(rotation: simd_quatf(angle: .pi * 2, axis: [0, 1, 0])),
15 duration: 10,
16 bindTarget: .transform
17 )
18 
19 if let animationResource = try? AnimationResource.generate(with: rotation) {
20 earth.playAnimation(animationResource.repeat())
21 }
22 
23 content.add(earth)
24 }
25 }
26 .gesture(
27 TapGesture()
28 .targetedToAnyEntity()
29 .onEnded { value in
30 // Entity'ye tıklandığında
31 let entity = value.entity
32 entity.scale *= 1.2 // Büyüt
33 }
34 )
35 }
36}

Spatial Interaction {#interaction}

swift
1struct InteractiveView: View {
2 @State private var selectedPlanet: Planet?
3 
4 var body: some View {
5 RealityView { content in
6 // Planets setup...
7 }
8 // Göz + pinch ile seçim
9 .gesture(
10 SpatialTapGesture()
11 .targetedToAnyEntity()
12 .onEnded { value in
13 handleSelection(value.entity)
14 }
15 )
16 // İki elle boyutlandırma
17 .gesture(
18 MagnifyGesture()
19 .targetedToAnyEntity()
20 .onChanged { value in
21 value.entity.scale = SIMD3(repeating: Float(value.magnification))
22 }
23 )
24 // Sürükle-bırak
25 .gesture(
26 DragGesture()
27 .targetedToAnyEntity()
28 .onChanged { value in
29 value.entity.position = value.convert(value.location3D, from: .local, to: .scene)
30 }
31 )
32 }
33}

visionOS'ta input yöntemleri:

Input
Kullanım
Precision
**Göz + Pinch**
Seçme, tıklama
Yüksek
**Direct Touch**
Yakın objelere dokunma
Çok yüksek
**Drag**
Taşıma, boyutlandırma
Orta
**Ses (Siri)**
Komut verme
Düşük

Immersive Spaces {#immersive-spaces}

Immersive Space, kullanıcının fiziksel mekanına 3D içerik yerleştirmeni sağlar. Üç immersion seviyesi vardır:

Immersion Style
Açıklama
Kullanım Alanı
**.mixed**
3D içerik + gerçek dünya birlikte
Eğitim, productivity, AR deneyimleri
**.progressive**
Kullanıcı kontrollü geçiş
Meditasyon, sanal turlar
**.full**
Tamamen sanal ortam
Oyunlar, sinematik deneyimler
swift
1struct ImmersiveExperienceView: View {
2 @State private var rotationAngle: Double = 0
3 
4 var body: some View {
5 RealityView { content in
6 // 3D ortam oluştur
7 let skybox = try? await Entity(named: "Starfield", in: realityKitContentBundle)
8 if let skybox {
9 skybox.position = [0, 1, -3]
10 content.add(skybox)
11 }
12 
13 // Ambient lighting ekle
14 let light = PointLight()
15 light.light.intensity = 5000
16 light.position = [0, 2, 0]
17 content.add(light)
18 } update: { content in
19 // State değiştiğinde sahneyi güncelle
20 if let entity = content.entities.first {
21 entity.transform.rotation = simd_quatf(
22 angle: Float(rotationAngle),
23 axis: [0, 1, 0]
24 )
25 }
26 }
27 .gesture(
28 RotateGesture3D()
29 .targetedToAnyEntity()
30 .onChanged { value in
31 rotationAngle = value.rotation.angle
32 }
33 )
34 }
35}
36 
37// Immersive Space'i açma/kapama
38struct SpaceController: View {
39 @Environment(\.openImmersiveSpace) var openSpace
40 @Environment(\.dismissImmersiveSpace) var dismissSpace
41 @State private var isImmersed = false
42 
43 var body: some View {
44 Toggle("Immersive Deneyim", isOn: $isImmersed)
45 .onChange(of: isImmersed) { _, newValue in
46 Task {
47 if newValue {
48 await openSpace(id: "immersiveExperience")
49 } else {
50 await dismissSpace()
51 }
52 }
53 }
54 }
55}

SharePlay ve Persona {#shareplay}

visionOS'ta SharePlay, birden fazla kullanıcının aynı spatial deneyimi paylaşmasını sağlar. Persona sistemi ile kullanıcılar FaceTime'da sanal temsilleriyle görünür:

swift
1import GroupActivities
2 
3struct WatchTogetherActivity: GroupActivity {
4 var metadata: GroupActivityMetadata {
5 var meta = GroupActivityMetadata()
6 meta.title = "Birlikte İzle"
7 meta.type = .watchTogether
8 return meta
9 }
10}
11 
12// Spatial Persona yerleşimi
13struct SharedSpaceView: View {
14 @State private var session: GroupSession<WatchTogetherActivity>?
15 
16 var body: some View {
17 RealityView { content in
18 // Paylaşılan 3D sahne
19 }
20 .task {
21 for await session in WatchTogetherActivity.sessions() {
22 self.session = session
23 session.join()
24 }
25 }
26 }
27}

visionOS Tasarım İlkeleri

İlke
Açıklama
Uygulama
**Ergonomi**
Kullanıcı konforunu koru
İçeriği göz hizasında tut, boyun yorgunluğunu önle
**Spatial Audio**
3D ses ile derinlik hissi
RealityKit AudioComponent kullan
**Glass Material**
visionOS'un görsel dili
`.glassBackgroundEffect()` tercih et
**Responsiveness**
Göz takibi geri bildirimi
Hover efektleri ekle

Existing App'leri Taşıma {#migration}

swift
1// Mevcut iOS app'ini visionOS'a taşımak çoğu zaman çok kolay:
2// 1. Xcode'da "Apple Vision Pro" destination ekle
3// 2. Build et - çoğu SwiftUI kodu çalışır!
4// 3. visionOS-specific özellikler ekle
5 
6// Platform kontrolü
7#if os(visionOS)
8 .ornament(attachmentAnchor: .scene(.trailing)) {
9 SidePanel()
10 }
11#else
12 .sheet(isPresented: $showPanel) {
13 SidePanel()
14 }
15#endif

Production Best Practices {#best-practices}

🔑 Çıkarımlar

  1. Window'dan başla - mevcut SwiftUI bilginle hemen uygulama yap
  2. Volume ile 3D içerik ekle - Model3D ile kolay
  3. Immersive Space dikkatli kullan - kullanıcı deneyimini bozmadan
  4. Göz takibi privacy korumalı - hangi öğeye baktığını bilemezsin
  5. Spatial audio unutma - 3D seste konum önemli
  6. Accessibility her platformda olduğu gibi kritik

Easter Egg

Gizli bir bilgi buldun!

Bu bölümde gizli bir bilgi var. Keşfetmek ister misin?

Okuyucu Ödülü

Tebrikler! Bu yazıyı sonuna kadar okuduğun için sana özel bir hediyem var:

ALTIN İPUCU

Bu yazının en değerli bilgisi

Bu ipucu, yazının en önemli çıkarımını içeriyor.

Etiketler

#visionos#spatial-computing#apple-vision-pro#realitykit#swiftui#ar-vr#advanced
Muhittin Çamdalı

Muhittin Çamdalı

Senior iOS Developer

12+ yıllık deneyime sahip iOS Developer. Swift, SwiftUI ve modern iOS mimarileri konusunda uzman. Apple platformlarında performanslı ve kullanıcı dostu uygulamalar geliştiriyorum.

iOS Geliştirme Haberleri

Haftalık Swift tips, SwiftUI tricks ve iOS best practices. Spam yok, sadece değerli içerik.

Gizliliğinize saygı duyuyoruz. İstediğiniz zaman abonelikten çıkabilirsiniz.

Paylaş

Bunu da begenebilirsiniz