标题有它... iOS 10 上有一个新声音,UIPickerView
每次更改所选项目时都会播放。有没有办法播放那个声音?理想情况下,AudioServicesPlaySystemSound(_)
如果有系统声音,或者没有任何其他方式。
问问题
1318 次
2 回答
5
我有同样的问题,我终于找到了解决方案
AudioServicesPlaySystemSoundWithCompletion(1157, nil);
AudioServicesPlaySystemSound
将在未来的版本中弃用。改为使用AudioServicesPlaySystemSoundWithCompletion
。
如果要模拟 UIPickerView 的声音和振动,还应该添加以下代码。
if (@available(iOS 10.0, *)) {
UIImpactFeedbackGenerator *impactFeedBack = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
[impactFeedBack prepare];
[impactFeedBack impactOccurred];
}
于 2019-05-21T08:28:36.077 回答
0
您可以使用系统点击声音或保存它们并从本地资源中使用
// NSURL *fileURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds/wheels_of_time.caf"]; // Too loud
// NSURL *fileURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds/nano/TimerWheelHoursDetent_Haptic.caf"]; // Hours tick
SystemSoundID soundID;
NSURL *fileURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds/nano/TimerWheelMinutesDetent_Haptic.caf"]; // Minutes tick
AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)fileURL, &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesDisposeSystemSoundID(soundID);
于 2017-03-30T07:26:52.807 回答