• SwiftUI 한 차원 높이기

    visionOS 앱에 깊이와 차원을 더해 보세요. 볼륨을 이용하여 앱에 3D 객체를 추가하는 방법을 알아보고, Model 3D API를 알아보고, 콘텐츠를 배치하고 애니메이션화하는 방법을 배워보세요. RealityView에서 UI attachment를 추가하고 콘텐츠에서 제스처를 지원하는 방법도 알아봅니다.

    챕터

    리소스

    관련 비디오

    WWDC23

  • 다운로드
    Array
    • 3:35 - MoonView

      struct MoonView {
        var body: some View {
          Model3D(named: "Moon") { phase in
            switch phase {
            case .empty:
              ProgressView()
            case let .failure(error):
              Text(error.localizedDescription)
            case let .success(model):
              model
                .resizable()
                .scaledToFit()
            }
          }
        }
      }
    • 17:26 - Manipulation Gesture

      // Gesture combining dragging, magnification, and 3D rotation all at once.
      var manipulationGesture: some Gesture<AffineTransform3D> {
          DragGesture()
              .simultaneously(with: MagnifyGesture())
              .simultaneously(with: RotateGesture3D())
              .map { gesture in
                  let (translation, scale, rotation) = gesture.components()
      
                  return AffineTransform3D(
                      scale: scale,
                      rotation: rotation,
                      translation: translation
                  )
              }
      }
      
      // Helper for extracting translation, magnification, and rotation.
      extension SimultaneousGesture<
          SimultaneousGesture<DragGesture, MagnifyGesture>,
          RotateGesture3D>.Value {
          func components() -> (Vector3D, Size3D, Rotation3D) {
              let translation = self.first?.first?.translation3D ?? .zero
              let magnification = self.first?.second?.magnification ?? 1
              let size = Size3D(width: magnification, height: magnification, depth: magnification)
              let rotation = self.second?.rotation ?? .identity
              return (translation, size, rotation)
          }
      }