美文网首页
iOS - 振动Feedback调研

iOS - 振动Feedback调研

作者: 温柔vs先生 | 来源:发表于2020-12-24 10:04 被阅读0次

UIFeedbackGenerator

UIFeedbackGenerator是整个震动反馈的核心,它只有一个方法

- (void)prepare;

他的作用就是让响应立刻发生,如果不调用这个方法的话,可能会发生延时,而且多次调用这个方法也没问题,他是安全的。

UINotificationFeedbackGenerator

UINotificationFeedbackGenerator才是真正需要我们写的东西,其实他里边的东西也不多,只有三个属性

UINotificationFeedbackTypeSuccess

UINotificationFeedbackTypeWarning

UINotificationFeedbackTypeError

分别在成功、警告和错误时调用。

具体的调用方法就是这样:

+ (void)executeSuccessFeedback

{

 UINotificationFeedbackGenerator *generator = [[UINotificationFeedbackGenerator alloc] init];

 [generator notificationOccurred:UINotificationFeedbackTypeSuccess];

}

UIImpactFeedbackGenerator

UIImpactFeedbackGenerator是另外一个类型的震动,同样也拥有三种形式

UIImpactFeedbackStyleLight

UIImpactFeedbackStyleMedium

UIImpactFeedbackStyleHeavy

分别是轻度、中度和重度。

调用的方法也很简单:

+ (void)excuteLightFeedback

{

 UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleLight];

 [generator prepare];

 [generator impactOccurred];

}

UISelectionFeedbackGenerator

UISelectionFeedbackGenerator中只有一个类型,是用来模拟选择滚轮一类控件时的震动,比如计时器中的picker滚动时就有这个效果。

+ (void)excuteSelectionFeedback

{

 UISelectionFeedbackGenerator *generator = [[UISelectionFeedbackGenerator alloc] init];

 [generator selectionChanged];

}

转载于:https://www.jianshu.com/p/a5e0d91f489b

相关文章

网友评论

      本文标题:iOS - 振动Feedback调研

      本文链接:https://www.haomeiwen.com/subject/nhnynktx.html