首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在iOS swift中显示ARSCNView中的集合视图

如何在iOS swift中显示ARSCNView中的集合视图
EN

Stack Overflow用户
提问于 2018-09-24 12:20:45
回答 1查看 251关注 0票数 2

我正在尝试在arscnview中实现uicollection视图,并在用户交互中水平滚动方向。在集合视图中,单元格包含产品图像和名称。是否可以添加集合视图arscnview。

我得到的结果是:

下面是我到目前为止编写的代码:

代码语言:javascript
运行
复制
     let newCollection: UICollectionView = {
    let layout = UICollectionViewFlowLayout()
    let collection = UICollectionView(frame: CGRect(x: 0, y: 0, width: 200, height: 100), collectionViewLayout: layout)
    layout.scrollDirection = .horizontal
    collection.backgroundColor = UIColor.gray
    collection.translatesAutoresizingMaskIntoConstraints = false
    collection.isScrollEnabled = true
    return collection
}()

  func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {

    DispatchQueue.main.async {
        guard let imageAnchor = anchor as? ARImageAnchor,
            let imageName = imageAnchor.referenceImage.name else { return }

   self.newCollection.delegate = self
            self.newCollection.dataSource = self
            self.newCollection.register(MyCollectionViewCell.self, forCellWithReuseIdentifier: self.cellId)
            self.view.addSubview(self.newCollection)
            self.setupCollection()

            let collectionPlane = SCNPlane(width: 0.2, height: 0.1)
            collectionPlane.firstMaterial?.diffuse.contents = self.newCollection

            let collectionNode = SCNNode(geometry: collectionPlane)
            collectionNode.eulerAngles.x = -.pi/2
            collectionNode.runAction(SCNAction.moveBy(x: 0, y: 0, z: 0, duration: 0))

            node.addChildNode(collectionNode)


                   self.sceneView.scene.rootNode.addChildNode(node)


   }

      //collection view

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
    return 7
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
    let cell = newCollection.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! MyCollectionViewCell
    cell.backgroundColor = .blue
    return cell
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    return CGSize(width: 100, height: 50)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {

    return UIEdgeInsets(top: 3, left: 3, bottom: 3, right: 3)
}

预期输出:

EN

回答 1

Stack Overflow用户

发布于 2019-06-25 15:13:19

将材质的漫反射内容属性设置为集合视图的视图属性

代码语言:javascript
运行
复制
let material = SCNMaterial()
material.diffuse.contents = yourCollectionView.view
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52472672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档