Reality Composer Pro之创建一个场景(一)
下载安装Reality Composer Pro
在今年的WWDC23上,为了帮助开发者更好的开发Version Pro的应用,Apple 推出Reality Composer Pro。
Apple 的官方介绍:
Discover the all-new Reality Composer Pro, designed to make it easy to preview and prepare 3D content for your visionOS apps. Available with Xcode, Reality Composer Pro can help you import and organize assets, such as 3D models, materials, and sounds. Best of all, it integrates tightly with the Xcode build process to preview and optimize your visionOS assets.
截止目前,Reality Composer Pro已经可以通过最新的Xcode 15.1 beta 3中获取使用。我们只需要下载对应的Xcode 版本。

然后,在Xcode 的顶部菜单栏中点击Xcode -> Open Developer Tools -> Reality Composer Pro即可。

SwiftUI之app的生命周期
在 SwiftUI之前,我们管理 app 的生命周期使用AppDelegate,这在使用 UIKit 开发时是非常常见的。在 iOS 13.0 之后,对于 SwifUI 的 app 可以使用AppDelegate和SceneDelegate来管理 app 的生命周期。1
2
3
4
5
6
7
8
9
10@main
struct AppLifeycleApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
RealityKit之创建一个AR应用
SwiftUI之实现App Store的Hero动画
最终实现的效果如下:
SceneKit基础之实现一个太阳系场景(二)
在上一篇文章中,我们已经通过Scene Editor实现了场景的布局。接下来我们将通过代码的方式来给节点添加图片材质、场景背景以及切换相机的视角。
定义模型和实现切换
定义一个名为Planet的枚举用来管理节点数据:1
2
3
4
5
6
7
8
9
10
11
12enum Planet: String, CaseIterable {
case mercury
case venus
case earth
case mars
case saturn
var name:String {
// 名字为首字母大写
rawValue.prefix(1).capitalized + rawValue.dropFirst()
}
}
SceneKit基础之实现一个太阳系场景(一)
在这篇博文中,我们将实现下面这样的一个效果:
在上面的效果中,使用SceneKit创建了一个 3D 的太阳系场景。在这个场景中,有我们常见的行星,然后我们还给场景设置了一个全场景的背景。最后就是通过下面的左右切换按钮可以切换视角查看不同的行星。
SceneKit之在SwiftUI中使用SceneKit
SceneKit is a high-level 3D graphics framework that helps you create 3D animated scenes and effects in your apps. It incorporates a physics engine, a particle generator, and easy ways to script the actions of 3D objects so you can describe your scene in terms of its content — geometry, materials, lights, and cameras — then animate it by describing changes to those objects.
来自 Apple 的官方文档的说法,SceneKit 是一个面向高层级 3D 图形框架,它可以帮助我们在app中创建一个3D 可变的场景和效果。它包括了物理引擎、粒子生成器以及更简单的给 3D 对象添加动作。
SwiftUI之使用 Combine 和 ViewModel 构建一个注册页面
SwiftUI中的状态管理
在 SwiftUI 中,响应式是区别于 UIKit 的一大特点。SwiftUI 中的响应式主要依赖与数据的状态来进行视图的更新和重绘。
@State
假设我们想要实现一个简单的计数功能,即点击➕按钮实现次数的加一。如下的代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15struct ContentView: View {
var count: Int = 0
var body: some View {
VStack(spacing: 10) {
Text("当前次数\(count)")
Button(action: {
}, label: {
Image(systemName: "plus")
.font(.title)
})
}
}
}
在上面的代码中,我们简单地在Button的action部分添加count += 1,如果我们这样做了,程序会报以下错误:
Left side of mutating operator isn’t mutable: ‘self’ is immutable



