iOS 操作触感震动 tab点击震动 按钮点击震动

其实很简单,主要是系统提供的几种震动方式

主要在这个AudioTool.framework

#import <AudioToolbox/AudioToolbox.h>

一般震动

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

普通短震(类似3D Touch的 Peek 反馈 )

AudioServicesPlaySystemSound(1519);

普通短震 (类似3D Touch Pop 反馈)

AudioServicesPlaySystemSound(1520);

连续三次短震

AudioServicesPlaySystemSound(1521);

iOS 10之后提供了一套Objective-C的接口

UIImpactFeedbackGenerator

这个枚举定义震动等级

typedef NS_ENUM(NSInteger, UIImpactFeedbackStyle) {
    UIImpactFeedbackStyleLight,
    UIImpactFeedbackStyleMedium,
    UIImpactFeedbackStyleHeavy,
    UIImpactFeedbackStyleSoft     API_AVAILABLE(ios(13.0)),
    UIImpactFeedbackStyleRigid    API_AVAILABLE(ios(13.0))
};
@interface UIImpactFeedbackGenerator : UIFeedbackGenerator

- (instancetype)initWithStyle:(UIImpactFeedbackStyle)style;

// 调用后立刻开始震动
- (void)impactOccurred;

// 调用后立刻开始震动,伴随着强度等级  0 到 1
- (void)impactOccurredWithIntensity:(CGFloat)intensity API_AVAILABLE(ios(13.0));

@end

使用方式

UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy];
[generator impactOccurred];
发布了352 篇原创文章 · 获赞 139 · 访问量 71万+

猜你喜欢

转载自blog.csdn.net/u013538542/article/details/105746776