小编elk*_*ner的帖子

如何在 RealityKit 中显示图库中的图像?

我想显示图库中的图像。我正在使用 imagePicker 加载图像。

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    guard let image = info[.originalImage] as? UIImage else { return }
  
    if let imgUrl = info[UIImagePickerController.InfoKey.imageURL] as? URL{            
        self.photoEntity = createPhotoEntity(fileUrl: imgUrl, fileName: imgName)
    }
    dismiss(animated: true)
}
Run Code Online (Sandbox Code Playgroud)

然后我创建了一个像这样的 modelEntity 。

private func createPhotoEntity(fileUrl: URL, fileName: String) -> ModelEntity? {
    // Create a TextureResource by loading the contents of the file URL.
    do {
        let texture = try TextureResource.load(contentsOf: fileUrl)
        let planeMesh = MeshResource.generatePlane(width: 0.5, depth: 0.5) …
Run Code Online (Sandbox Code Playgroud)

augmented-reality swift arkit realitykit

5
推荐指数
1
解决办法
949
查看次数

如何停止计时器发布者?

我在操场上玩了一段时间的计时器发布者。下面是我的代码

let timer = Timer
    .publish(every: 1.0, on: .main, in: .common)
.autoconnect()

var counter = 0
let subscriber = timer
    .map({ (date) -> Void in
        counter += 1
    })
    .sink { _ in

        print("I am printing the counter \(counter)")
}

if counter > 5 {
    timer.upstream.connect().cancel() //1.nothing happened
    subscriber.cancel() //2. nothing happened too. :(
}
Run Code Online (Sandbox Code Playgroud)

但是我无法通过使用第 1 行和第 2 行来停止计时器。我实际上错过了什么?

swift combine

1
推荐指数
1
解决办法
1039
查看次数

标签 统计

swift ×2

arkit ×1

augmented-reality ×1

combine ×1

realitykit ×1