iOS中的单例模式
来源:互联网 发布:马克飞象 mac客户端 编辑:程序博客网 时间:2024/06/05 19:28
本demo主要功能是创建一个把虚拟的画挂在墙上:
语言:Swift
效果图:
注意3点 : 需要iPhone6s及以上手机 ,至少iOS 11以上系统, 必须真机运行
主要是代码和注释 部分如下
1 引入头文件
1
2
3
4
//引入ARkit所需的包
import
ARKit
//引入 SceneKit
import
SceneKit
2 代理和属性
1
2
3
4
5
6
7
8
9
10
class
ArtTreeViewController: UIViewController,ARSCNViewDelegate {
//必备
let arSCNView = ARSCNView()
let arSession = ARSession()
let arConfiguration = ARWorldTrackingConfiguration()
//用来显示图的节点
let ArtPicNode = SCNNode()
.........
}
3.设置显示场景的背景view
1
2
3
4
5
6
7
8
//设置arSCNView属性
arSCNView.frame = self.view.frame
arSCNView.session = arSession
arSCNView.automaticallyUpdatesLighting =
true
//自动调节亮度
self.view.addSubview(arSCNView)
arSCNView.delegate = self
4.创建一个长方体,并把图片覆盖到其表面
1
2
3
4
5
6
7
8
9
10
11
//创建一个长方体,用来展示图片
ArtPicNode.geometry = SCNBox.init(width: boxW, height: boxH, length: boxL, chamferRadius:
0.1
)
//方形
//把图片覆盖到其表面
ArtPicNode.geometry?.firstMaterial?.diffuse.contents = timgKuang.jpg
ArtPicNode.geometry?.firstMaterial?.multiply.intensity =
0.5
//強度
ArtPicNode.geometry?.firstMaterial?.lightingModel = SCNMaterial.LightingModel.constant
//3.设置位置:相对于摄像头
ArtPicNode.position = SCNVector3(
0
,
5
, -
20
)
//添加长方体到界面上
self.arSCNView.scene.rootNode.addChildNode(ArtPicNode)
阅读全文
0 0
- iOS中的单例模式
- IOS中的单例模式
- IOS 中的单例模式
- iOS中的单例模式
- iOS中的单例模式
- iOS中的单例模式
- iOS中的单例模式
- iOS中的单例模式
- IOS中的单例模式
- IOS中的单例模式
- iOS中的单例模式
- iOS 中的单例模式
- iOS中的单例模式
- iOS中的单例模式
- ios中的单例模式
- iOS中的单例模式
- iOS中的单例模式
- iOS中的单例模式
- firefox中Date.prase()解析 'Y-m-d'格式的时间, 返回NaN的问题
- 安装codeblocks(win10)
- js去掉最后一个逗号
- sql语句之多个ORDER BY
- 遍历文件夹下的文件夹和子文件,遍历文件夹删除文件夹及其下面的所有子文件
- iOS中的单例模式
- Erlang进程错误处理的术语含义
- APICloud 如何实现将UIScrollPicture 模块添加到指定元素里面
- Elasticsearch 优化实施方法
- Error:Execution failed for task ':clean'. > Unable to delete directory :\build\intermediates
- Access数据库数据表导入到mysql数据库流程
- Hbase shell 常用命令
- java8实战二:Lambda 表达式
- 清除浮动