Can I disable UIPickerView scroll sound?
Asked Answered
E

8

11

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

Ehrman answered 17/9, 2009 at 23:26 Comment(0)
M
5

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.

Megdal answered 5/4, 2010 at 6:22 Comment(0)
C
7

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.

Cattail answered 4/11, 2010 at 4:35 Comment(2)
Great answer! I've been trying to figure this out a long time.Submicroscopic
This works great, except that you can't animate the wheels. I tried this with animation enabled, but changing the view hierarchy kills the animation.Manner
M
5

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.

Megdal answered 5/4, 2010 at 6:22 Comment(0)
R
2

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

Reprise answered 10/3, 2010 at 9:24 Comment(0)
M
2

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);
}
Manner answered 13/3, 2014 at 16:31 Comment(1)
Your example is written in a very future-safe way, but I'm not sure that obfuscating code to get around Apple's checks is a good idea. I worry that the punishment for a deliberate attempt to circumvent their API checks may be harsh.Caffrey
Q
1

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.

Quillon answered 17/9, 2009 at 23:59 Comment(5)
that works perfectly! thank you so much!! By the way, do you know how particular Apple is with shunning undocumented API? This needs to hit the App store soon. Wouldn't wanna be rejected and dejected because of a thing so small :)Ehrman
" By the way, do you know how particular Apple is with shunning undocumented API?" I really don't know the answer to that question, try searching it on SO and if it hasn't already been asked, ask it.Quillon
They currently warn you if you use this method.Swenson
you always get warnings that your object may not respond to undocumented messages because they are implemented but not exposed in the header file. So that is completely expected given the fact that the solution I gave was undocumented :)Quillon
I have had 2 application updates rejected because of this particular API callOmnivore
M
1

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://mcmap.net/q/80581/-avfoundation-how-to-turn-off-the-shutter-sound-when-capturestillimageasynchronouslyfromconnection

Manner answered 23/5, 2014 at 18:18 Comment(0)
E
1

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];
Eritrea answered 23/10, 2015 at 11:55 Comment(1)
Here's the correct code: NSDate *minimumDate = [[NSDate date] dateByAddingTimeInterval:300]; if ([datePickerCustomTime.date laterDate:minimumDate] == minimumDate) { [datePickerCustomTime setDate:minimumDate animated:NO]; } datePickerCustomTime.minimumDate = minimumDate;Puppetry
S
0

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

Sandhog answered 19/3, 2015 at 7:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.