修复震动反馈初始化和调用逻辑,确保在点击事件中及时响应震动反馈。同时新增准备震动反馈的方法以提升用户体验和代码可维护性。

This commit is contained in:
edwinQQQ
2025-08-28 17:08:57 +08:00
parent 24a4e75fae
commit c9df21a005

View File

@@ -74,7 +74,11 @@
- (instancetype)init {
if (self = [super init]) {
self.feedbackGenerator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy];
// 🔥
if (@available(iOS 10.0, *)) {
self.feedbackGenerator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy];
[self.feedbackGenerator prepare]; // 🔥 prepare
}
self.updateGoldQueue = @[].mutableCopy;
@@ -299,10 +303,26 @@
NSLog(@"[Combo effect] ⚠️ 点击间隔过短,忽略此次点击");
return;
}
// 🔥
if (@available(iOS 10.0, *)) {
if (self.feedbackGenerator) {
@try {
[self.feedbackGenerator impactOccurred];
NSLog(@"[Combo effect] 📳 震动反馈已触发");
} @catch (NSException *exception) {
NSLog(@"[Combo effect] ⚠️ 震动反馈失败: %@", exception.reason);
}
} else {
NSLog(@"[Combo effect] ⚠️ 震动反馈生成器未初始化");
}
} else {
NSLog(@"[Combo effect] ⚠️ 设备不支持震动反馈 (iOS < 10.0)");
}
#if RELEASE
isHandlingTap = YES;
#endif
[self.feedbackGenerator impactOccurred];
NSLog(@"[Combo effect] 👆 连击面板被点击,发送礼物");
@@ -330,6 +350,16 @@
[[GiftComboManager sharedManager] clear];
}
// 🔥
- (void)prepareFeedbackGenerator {
if (@available(iOS 10.0, *)) {
if (self.feedbackGenerator) {
[self.feedbackGenerator prepare];
NSLog(@"[Combo effect] 📳 震动反馈已重新准备");
}
}
}
// SVGAPlayerDelegate:
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player {
[self.playImageView stepToPercentage:0 andPlay:NO];