柚子快報(bào)邀請(qǐng)碼778899分享:iOS 添加震動(dòng)效果
1. AudioServicesPlaySystemSound
較早的系統(tǒng)版本,我們會(huì)使用AudioTool.framework。
#import
一般震動(dòng)
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
普通短震(類似3D Touch的 Peek 反饋 )
AudioServicesPlaySystemSound(1519);
普通短震 (類似3D Touch Pop 反饋)
AudioServicesPlaySystemSound(1520);
連續(xù)三次短震
AudioServicesPlaySystemSound(1521);
2. UIImpactFeedbackGenerator
iOS 10之后提供了UIImpactFeedbackGenerator
@interface UIImpactFeedbackGenerator : UIFeedbackGenerator
- (instancetype)initWithStyle:(UIImpactFeedbackStyle)style;
// 調(diào)用后開(kāi)始震動(dòng)
- (void)impactOccurred;
// 調(diào)用后開(kāi)始震動(dòng),強(qiáng)度從0~1
- (void)impactOccurredWithIntensity:(CGFloat)intensity API_AVAILABLE(ios(13.0));
@end
UIImpactFeedbackStyle定義了震動(dòng)的等級(jí)
typedef NS_ENUM(NSInteger, UIImpactFeedbackStyle) {
UIImpactFeedbackStyleLight,
UIImpactFeedbackStyleMedium,
UIImpactFeedbackStyleHeavy,
UIImpactFeedbackStyleSoft API_AVAILABLE(ios(13.0)),
UIImpactFeedbackStyleRigid API_AVAILABLE(ios(13.0))
};
UIImpactFeedbackGenerator使用
UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
[generator prepare];
[generator impactOccurred];
柚子快報(bào)邀請(qǐng)碼778899分享:iOS 添加震動(dòng)效果
推薦鏈接
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場(chǎng)。
轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。