我可以禁用 UIPickerView 滚动声音吗?

发布于 2024-08-05 06:27:20 字数 182 浏览 7 评论 0原文

我想禁用 UIPickerView 在上下滚动时生成的烦人的点击。有办法做到这一点吗?我想为选择器视图降落的每个项目播放简短的声音。它会被内置声音毁掉。

据我了解,可以通过在 iPhone/iPod 设置中关闭键盘声音来全局关闭选择器声音。但有没有办法以编程方式做到这一点?

任何帮助将不胜感激!

谢谢

I want to disable the annoying clicks that the UIPickerView generates upon scrolling up and down. Is there a way to do this? I want to play short sounds for each item that the picker view lands upon. It gets ruined by the built in sound.

I understand that the picker sounds can be turned off globally by switching off the keyboard sounds in iPhone/iPod settings. But is there a way to programatically do this?

Any help will be much appreciated!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

浅笑轻吟梦一曲 2024-08-12 06:27:20

我一直在努力解决 UIPickerView 声音问题,尽管它仅与原始问题部分相关,但我在这里发布问题/解决方案,因为这个主题不断出现在我的搜索结果中,所以我认为其他人也有同样的问题船也可能会停在这里……

我需要初始化 UIPickerView 以从保存的数据中恢复当前选定的行。很简单,对吧?在 viewDidLoad 中,只需调用 UIPickerView 的 selectRow:inComponent:animated 方法:

[myPicker selectRow:currentRowIndex inComponent:0 animated:NO];

这会按预期工作,但有一个副作用,它会生成单个“单击”声音,就好像用户滚动了控件一样。仅当在设备(而不是模拟器)上运行时才会出现点击声,并且仅当设备安装了 iOS 3.x 时才会出现(我使用 3.1.3 和 3.2 进行了测试)。这显然是 iOS 中的一个错误,从 iOS 4.0 开始修复。但如果您需要针对 Gen1 iPhone,则只能使用存在此问题的 iOS 3.1.3。

我与 Apple DTS 讨论了这个问题,但除了升级到 4.0 之外,他们无法提出任何解决方法。我问他们是否会破例并允许使用上面提到的未记录的 setSoundsEnabled (这实际上解决了问题)。答案是:“没有例外。”

经过一些额外的侦探工作,我发现可以通过暂时从超级视图中删除 UIPickerView、调用 selectRow,然后将其重新添加到超级视图来防止声音发生。例如,在 viewDidLoad 中:

UIView *superview = [myPicker superview];
[myPicker removeFromSuperview];

[myPicker reloadAllComponents];
[myPicker selectRow:currentRowIndex inComponent:0 animated:NO];

[superview addSubview:myPicker];

这在不使用未记录/私有 API 的情况下消除了无关的点击声音,因此应该通过 Apple 的批准流程。

I've been struggling with a UIPickerView sound issue, and even though it's only partially relevant to the original question, I'm posting the problem/solution here because this topic keeps coming up in my search results so I think anyone else in the same boat may end up here too…

I needed to initialize a UIPickerView to restore the currently selected row from saved data. Simple, right? In viewDidLoad, just call the selectRow:inComponent:animated method of UIPickerView:

[myPicker selectRow:currentRowIndex inComponent:0 animated:NO];

This works as expected, but has a side effect that it generates a single "click" sound as if the user had scrolled the control. The click sound only occurs when running on a device (not the simulator), and only if the device has iOS 3.x installed (I tested with 3.1.3 and 3.2). This was apparently a bug in iOS that was fixed starting with iOS 4.0. But if you need to target Gen1 iPhone, you're stuck with iOS 3.1.3 where this problem is present.

I discussed the issue with Apple DTS, but they were unable to suggest any workaround other than upgrading to 4.0. I asked if they would make an exception and permit the use of the undocumented setSoundsEnabled mentioned above (which does actually solve the problem). The answer was, "There are no exceptions."

After some additional detective work, I discovered that you can prevent the sound from occurring by temporarily removing the UIPickerView from the superview, call selectRow, then re-add it to the superview. For example, in viewDidLoad:

UIView *superview = [myPicker superview];
[myPicker removeFromSuperview];

[myPicker reloadAllComponents];
[myPicker selectRow:currentRowIndex inComponent:0 animated:NO];

[superview addSubview:myPicker];

This gets rid of the extraneous click sound without using undocumented/private APIs so should pass Apple's approval process.

海的爱人是光 2024-08-12 06:27:20

在 App Store 上使用这个特定的未记录的 api 一年多后,苹果终于要求我将其从我的应用程序中删除。对于音频应用程序来说,发出那种该死的点击声是非常令人沮丧的。最好的建议是与用户分享,可以在“声音”下的设置应用程序中全局禁用选择器声音,并将“键盘点击”设置为“关闭”。我还强烈建议访问 https://bugreport.apple.com/ 并提交 UIPickerView 的错误,因为它当播放选择器点击时,可能会导致音频应用程序失真。

After using this specific undocumented api for over a year on the App Store Apple finally asked me to remove it from my App. It is very frustrating for audio apps to have that damn click sound. The best advice is to share with users that the picker sound can be disabled globally in the settings application under "Sounds" and setting "Keyboard Clicks" to "Off". I also strongly recommend visiting https://bugreport.apple.com/ and filing a bug for UIPickerView, as it can cause distortion in audio applications when the picker click is played.

清引 2024-08-12 06:27:20

他们刚刚拒绝了我的一个应用程序,因为使用了未记录的 API……这就是其中之一。

they have just rejected an app of mine because the use of undocumented api's...thats one of them.

北恋 2024-08-12 06:27:20

我认识的人说他上周刚刚通过了 App Store 审核:

// Hide private API call from Apple static analyzer
SEL sse = NSSelectorFromString([NSString stringWithFormat:@"%@%@%@", @"set",@"Sounds",@"Enabled:"]);
if ([UIPickerView instancesRespondToSelector:sse]) {
    IMP sseimp = [UIPickerView instanceMethodForSelector:sse];
    sseimp(self.thePicker, sse, NO);
}

Someone I know says he got this past the App Store review just last week:

// Hide private API call from Apple static analyzer
SEL sse = NSSelectorFromString([NSString stringWithFormat:@"%@%@%@", @"set",@"Sounds",@"Enabled:"]);
if ([UIPickerView instancesRespondToSelector:sse]) {
    IMP sseimp = [UIPickerView instanceMethodForSelector:sse];
    sseimp(self.thePicker, sse, NO);
}
烂人 2024-08-12 06:27:20

有一种未记录的方法(我实际上不确定它在iphone 3.0中是否仍然可用),但这里有任何方法

#import <UIKit/UIKit.h>

@interface SilintUIPickerView: UIPickerView
{ }

- (void) setSoundsEnabled: (BOOL) enabled;
@end

可以使用这个子类来代替并调用[view setSoundsEnabled: NO]< /code>

我有兴趣了解它在最新 SDK 中的表现,请尝试一下并告诉我们。

There is an undocumented way (I'm actually not sure if it is still available in iphone 3.0) but here it is any way

#import <UIKit/UIKit.h>

@interface SilintUIPickerView: UIPickerView
{ }

- (void) setSoundsEnabled: (BOOL) enabled;
@end

use this subclass instead and call [view setSoundsEnabled: NO]

I'm interested in knowing how it goes in the latest SDK, give it a shot and let us know.

把昨日还给我 2024-08-12 06:27:20

这招能管用吗?有人能够通过同时播放声音的倒置副本来抑制相机快门声音效果:https://stackoverflow.com /a/23758876/214070

Could this trick work? Someone was able to suppress the camera shutter sound effect by playing an inverted copy of the sound at the same moment: https://stackoverflow.com/a/23758876/214070

迷乱花海 2024-08-12 06:27:20

也许这不是这个特定问题的答案,但我有一个类似的问题 - 设置 datePicker 的最小日期,我想设置它而不需要烦人的“点击”声音。一段时间后发现非常简单的解决方案:

datePickerCustomTime.minimumDate = [[NSDate date] dateByAddingTimeInterval:300]// min time to set = now + 5 min
  [datePickerCustomTime setDate:[[NSDate date] dateByAddingTimeInterval:300] animated:NO];

Maybe this not the answer for this particular question, but I had a similar problem - set minimumDate for datePicker, and I wanted set it without annoying "click" sound. After some time found very simple solution:

datePickerCustomTime.minimumDate = [[NSDate date] dateByAddingTimeInterval:300]// min time to set = now + 5 min
  [datePickerCustomTime setDate:[[NSDate date] dateByAddingTimeInterval:300] animated:NO];
水染的天色ゝ 2024-08-12 06:27:20

我找到了这个尝试的小快速解决方案,下面

        UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, yPickerView, VIEW_WIDTH, PICKERVIEW_HEIGHT)];
        pickerView.delegate = self;
        pickerView.dataSource = self;
        pickerView.showsSelectionIndicator = YES;
        pickerView.alpha = 0.8f;
        pickerView.tag = fieldTag;
        [pickerView selectRow:pickerViewSelectedIndex inComponent:0 animated:NO];

为 selectRow: 方法设置动画:NO

I found small quickie solution for this try below

        UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, yPickerView, VIEW_WIDTH, PICKERVIEW_HEIGHT)];
        pickerView.delegate = self;
        pickerView.dataSource = self;
        pickerView.showsSelectionIndicator = YES;
        pickerView.alpha = 0.8f;
        pickerView.tag = fieldTag;
        [pickerView selectRow:pickerViewSelectedIndex inComponent:0 animated:NO];

set the animated:NO for selectRow: method

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文