swift - iOS10之后的加速器
import UIKit //1.加速器框架
import CoreMotion class ViewController: UIViewController { //1.创建运动管理者 必须设置为 全局的
let manager = CMMotionManager() override func viewDidLoad() {
super.viewDidLoad() //2.判断加速计是否可用
if !manager.isAccelerometerAvailable{
print("加速计不可用")
return
} //设置采集间隔
// manager.accelerometerUpdateInterval = 1
manager.accelerometerUpdateInterval = 1.0/2 //3.开始采集
manager.startAccelerometerUpdates() // //push:主动告诉外界数据
// manager.startAccelerometerUpdates(to: OperationQueue.main) { (data:CMAccelerometerData?, err:Error?) in
// if err == nil{
// print(data)
// print(data?.acceleration.x, data?.acceleration.y, data?.acceleration.z)
// }
// } } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { //这里必须 执行 manager.startAccelerometerUpdates() 才有数据
print(manager.accelerometerData?.acceleration.x, manager.accelerometerData?.acceleration.y, manager.accelerometerData?.acceleration.z)
}
}
swift - iOS10之后的加速器的更多相关文章
- SwiftUI - iOS10本地推送通知教程UserNotifications在Swift中的实现方式
简介 消息推送相信在很多人的眼里都不陌生了吧?像即时聊天微信,好友发信息给你时会在顶部弹下小窗口提醒你.也像是在影院APP预订了电影票,在开场前一小时你也会收到提醒.这类推送是需要经过后端发送请求的, ...
- Swift:一个简单的货币转换器App在iOS10中的分析和完善
这本不算是一个完整的货币转换App,只不过是一个小巧的学习性质的程序.该App覆盖了如下几个知识点: 多国语言的支持 通过网络Api接口读取数据 最后我们来修复一个原来代码中的一个小错误作为完美的收尾 ...
- iOS10.0 & Swift 3.0 对于升级项目的建议
iOS & Swift新旧版本更替, 在Apple WWDC大会开始之际, 也迎来了iOS 10.0, Swift 3.0 测试版, 到目前为止, 已经是测试版2.0, 每次更新都带来了新的语 ...
- swift - 加速器/摇一摇功能
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...
- fir.im Weekly - 关于 iOS10 适配、开发、推送的一切
"小程序"来了,微信变成名副其实的 Web OS,新一轮的Web App 与Native App争论四起.程序员对新技术永远保持灵敏的嗅觉和旺盛的好奇心,@李锦发整理了微信小程序资 ...
- iOS开发 适配iOS10
2016年9月7日,苹果发布iOS 10.2016年9月14日,全新的操作系统iOS 10将正式上线. 作为开发者,如何适配iOS10呢? 1.Notification(通知) 自从Notificat ...
- Swift和Objective-C混编注意事项
前言 Swift已推出数年,与Objective-C相比Swift的语言机制及使用简易程度上更接地气,大大降低了iOS入门门槛.当然这对新入行的童鞋没来讲,的确算是福音,但对于整个iOS编程从业者来讲 ...
- Swift 之模糊效果(毛玻璃效果,虚化效果)的实现
前言: 之前项目中有用到过Objective-C的的模糊效果,感觉很是不错,而且iOS8之后官方SDK也直接提供了可以实现毛玻璃效果的三个类:UIBlurEffect.UIVibrancyEffect ...
- 【转】iOS学习之适配iOS10
适配iOS10 2016年9月7日,苹果发布iOS 10.2016年9月14日,全新的操作系统iOS 10将正式上线. 作为开发者,如何适配iOS10呢? 1.Notification(通知) 自从N ...
随机推荐
- 关于cordova 状态栏设置
https://blog.csdn.net/u011127019/article/details/58104056
- 跨域(五)——postMessage
HTML5的postMessage机制是客户端最直接的中档传输方法,一般用在iframe中父页与子页之间的客户端跨域通信. 浏览器支持情况:Chrome 2.0+.Internet Explorer ...
- Visual Studio for Mac 使用笔记
无法打开控制台运行程序 Project -> Project Options -> Run -> Configurations -> Default 勾选Run on exte ...
- LeetCode OJ 145. Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary t ...
- week05 05restful api
和第一个项目一样 然后去App.js注册一下 但是呢 新闻是写死在 现在主要输调通前端client和后端server 持续获取新闻 至于真假先不考虑 下面我们回到前端NewsPanel 这个reque ...
- Ajax 学习 第四篇
使用jQuery实现Ajax 跨域
- C++ CBitmap,HBitmap,Bitmap区别及联系
加载一位图,可以使用LoadImage: HANDLE LoadImage(HINSTANCE hinst,LPCTSTR lpszName,UINT uType,int cxDesired,int ...
- ArcGIS 10安装及破解
1.下载 ArcGIS 10 安装程序及破解文件后面提供电驴的下载地址(可以使用迅雷.QQ旋风等下载工具下载),下载文件是一个光盘镜像文件:? ArcGIS_Desktop10_122519.iso. ...
- SQL Server 生成 数据字典 / 数据库文档
1. 工具生成 2.SQL语句生成 参考地址:http://blog.csdn.net/qq289523052/article/details/22174721 1.在 表 上右键 - 扩展属性 - ...
- Compute Shader
[Compute Shader] 1.Similar to regular shaders, compute shaders are Asset files in your project, with ...