Watch OS 2 中 Taptic Engine 的开发教程
2015-07-20 19:01
405 查看
在WWDC2015上,Apple发布了Watch OS 2,增加了Taptic Engine的访问
先上核心代码
超级简单是不是?就一句是不是?秒懂有木有!
那么我们来讲一讲最后一个参数
WKHapticType一共有9种
它们分别是
Notification //这是在Apple Watch接受通知时的震动
DirectonUp //上滑到头的震动
DirectionDown //下滑到头的震动
Success //成功返回的震动
Failure //失败返回的震动
Retry //表示重试的震动
Start //表示开始的震动
Stop //表示停止的震动
Click //轻击的震动
高考水平的单词,大家应该都懂是什么意思,但造福人民,我还是注释一下
那么怎么用呢
我来举个例子
就是在这个语句执行后Apple Watch会用线性致动器轻击你的手腕
想记住它很简单:(Watch Kit Interface Device)Current Device Play Haptic
好,那么我们把它们带入到应用中去
1.新建一个watch os 2 project
2.打开watch的故事版
3.放置3个Group到ViewController上
4.设置所有group的height(在旁边的检查器)为relative to container并将数值写为0.33
5.拖入一个button,在同样的地方设置width的值为0.33,一组放三个,并起一个你喜欢的名字(能辨认出哪个是哪个即可)
6.在interface controller中加入以下代码
如图所示
7.然后在view controller里关联好ibaction
8.运行你的应用吧
先上核心代码
WKInterfaceDevice.currentDevice().playHaptic(type: WKHapticType)
超级简单是不是?就一句是不是?秒懂有木有!
那么我们来讲一讲最后一个参数
WKHapticType一共有9种
它们分别是
Notification //这是在Apple Watch接受通知时的震动
DirectonUp //上滑到头的震动
DirectionDown //下滑到头的震动
Success //成功返回的震动
Failure //失败返回的震动
Retry //表示重试的震动
Start //表示开始的震动
Stop //表示停止的震动
Click //轻击的震动
高考水平的单词,大家应该都懂是什么意思,但造福人民,我还是注释一下
那么怎么用呢
我来举个例子
WKInterfaceDevice.currentDevice().playHaptic(.Click)
就是在这个语句执行后Apple Watch会用线性致动器轻击你的手腕
想记住它很简单:(Watch Kit Interface Device)Current Device Play Haptic
好,那么我们把它们带入到应用中去
1.新建一个watch os 2 project
2.打开watch的故事版
3.放置3个Group到ViewController上
4.设置所有group的height(在旁边的检查器)为relative to container并将数值写为0.33
5.拖入一个button,在同样的地方设置width的值为0.33,一组放三个,并起一个你喜欢的名字(能辨认出哪个是哪个即可)
6.在interface controller中加入以下代码
@IBAction func Notification() { WKInterfaceDevice.currentDevice().playHaptic(.Notification) } @IBAction func DirectionUp() { WKInterfaceDevice.currentDevice().playHaptic(.DirectionUp) } @IBAction func DirectionDown() { WKInterfaceDevice.currentDevice().playHaptic(.DirectionDown) } @IBAction func Success() { WKInterfaceDevice.currentDevice().playHaptic(.Success) } @IBAction func Failure() { WKInterfaceDevice.currentDevice().playHaptic(.Failure) } @IBAction func Retry() { WKInterfaceDevice.currentDevice().playHaptic(.Retry) } @IBAction func Start() { WKInterfaceDevice.currentDevice().playHaptic(.Start) } @IBAction func Stop() { WKInterfaceDevice.currentDevice().playHaptic(.Stop) } @IBAction func Click() { WKInterfaceDevice.currentDevice().playHaptic(.Click) }
如图所示
7.然后在view controller里关联好ibaction
8.运行你的应用吧
相关文章推荐
- Extjs4.0 最新最全视频教程
- OpenERP 的XML-RPC的实例+many2many,one2many,many2one...
- CSS3属性教程与案例分享
- jquery教程靠边站,一分钱不花让你免费学会jquery
- 如何成为一名专家级的开发人员
- autoit入门教程小结第1/5页
- 用Photoshop 制作草地效果简明教程
- 比较完整简洁的Flash处理XML文档数据教程 上篇第1/3页
- VBS基础编程教程 (第1篇)
- SQLite教程(十一):临时文件
- VBS基础编程教程 (第3篇)
- VBS教程:运算符-运算符(+)
- PostgreSQL教程(十):性能提升技巧
- PostgreSQL教程(二):模式Schema详解
- PostgreSQL教程(十三):数据库管理详解
- PostgreSQL教程(八):索引详解
- PostgreSQL教程(三):表的继承和分区表详解
- XML简易教程之三
- ruby 数组使用教程
- PostgreSQL教程(十九):SQL语言函数