Taptic Engine

先了解一个概念——Taptic Engine

Taptic Engine 是苹果产品上推出的全新震动模块,该元件最早出现在 Apple Watch 中。iPhone 6s 和 iPhone 6s Plus 中,也同样内置了Taptic Engine,在设计上有所升级。

Taptic Engine 振动模块为 Apple Watch 以及 iPhone 6s、iPhone 7 提供了 Force Touch 以及 3D Touch,不同的屏幕操作,可以感受到不同的振动触觉效果,带来更好的用户体验。

震动反馈(UIFeedbackGenerator)

震动反馈是iOS 10之后出的新特性,相比于之前的系统震动

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)

要友好得多,没有声音,震动幅度适中,不需要设置里“响铃模式震动”打开。这也是Apple更推荐开发者使用的反馈震动。

e.g. Switch控件滑动,时钟里选时间滑动,产生的震动都是UIFeedbackGenerator特性的。

现在“震动反馈”的应用是非常广的 —— 下拉刷新;点击重要的Button;选择器等等。都可以加上反馈。

Apple文档(UIFeedbackGenerator)

//
// UIImpactFeedbackGenerator.h
// UIKit
//
// Copyright © 2016 Apple Inc. All rights reserved.
//

#import <UIKit/UIFeedbackGenerator.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, UIImpactFeedbackStyle) {
 UIImpactFeedbackStyleLight,
 UIImpactFeedbackStyleMedium,
 UIImpactFeedbackStyleHeavy
};

// UIImpactFeedbackGenerator is used to give user feedback when an impact between UI elements occurs
UIKIT_CLASS_AVAILABLE_IOS_ONLY(10_0) @interface UIImpactFeedbackGenerator : UIFeedbackGenerator

- (instancetype)initWithStyle:(UIImpactFeedbackStyle)style;

/// call when your UI element impacts something else
- (void)impactOccurred;

@end

想要用震动反馈也特别简单:

UIImpactFeedbackGenerator *feedBackGenertor = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
[feedBackGenertor impactOccurred];

注意: “UIImpactFeedbackGenerator’ is only available on iOS 10.0 or newer”,使用的时候加上版本限制。**

手机 — 设置 — 声音与触感 — 系统触感反馈(打开)

此前系统震动AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)

在iOS 10之前,系统震动采用的是震动+铃声的模式,目前看来是及其不友好的,首先震动略大,其次带声音,体验并不好。但这种的方式可以自定义音效。

Apple文档(AudioServicesPlaySystemSound)

#import <AudioToolbox/AudioToolbox.h> 

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

注意:手机 — 设置 — 声音与触感 — 响铃模式震动(打开)

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对我们的支持。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。