UIToolBar unexpectedly registers taps on instances of UIBarButtonItem, even when they click a considerable distance from them

I wonder if anyone noticed this behavior - searching the Internet or these forums have not canceled anything for me:

[Update: the problem still exists on the iPhone (but not on iPads), as on iOS 7.0.1]

On an iPhone app on iOS 4.2.1, at least up to 3.2 (in the simulator) if you have a toolbar ( UIToolBar — explicitly created or provided by the UINavigationController ) filled with UIBarButtonItem instances of the UIBarButtonItemStyleBordered style (rectangular buttons with rounded borders)
- and you have a significant empty space between them (for example, using an instance of UIBarButtonItem system type UIBarButtonSystemItemFlexibleSpace between two buttons to put it in the far left position and the other on the right) w> I observe the following unexpected behavior:

If you touch an empty space on the toolbar with a considerable distance from the nearest button , this button - unexpectedly - still registers a short press on strong>.

Although you can read this function, it can also be confusing for users, especially if the location of the tap does not give a clear indication of which function is being called. In "thick settlements" where random taps are likely (for example, a game whose elements border the toolbar), this behavior increases the likelihood of accidentally calling functions.

In my particular case, you can click up to 56 pixels to the right of the button and still register the tap.

This behavior occurs both in the simulator and on real devices. Has anyone else had this experience? Am I missing something?

Thanks for listening / help.

+4
source share
3 answers

I see how this would be useful in some cases, but unexpectedly in others. Please review the bug issue with Apple at http://radar.apple.com .

0
source

I also found that this is quite a problem (I have a button located directly above the UIToolBar, and I found that most of the time, when I tried to click on this button with my thumb, I ended up in an empty space in the UIToolbar and activated one of the buttons toolbars).

The only way I could find to avoid this problem was to install a function button between the buttons and the flexible space. Thus, any touches within the flexible space simply activate the function button and nothing will happen. I implemented this with a UIBarButtonItem initWithCustomView and just used a UIImageView with a 1x1 transparent image (forgive me!):

 [myToolbar setItems:[NSArray arrayWithObjects: [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease], [[[UIBarButtonItem alloc] initWithCustomView: [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1x1Transparent.png"]] autorelease]] autorelease], [[[UIBarButtonItem alloc] initWithTitle:@"Button 1" style:UIBarButtonItemStyleBordered target:self action:@selector(button1Pressed:)] autorelease], [[[UIBarButtonItem alloc] initWithTitle:@"Button 2" style:UIBarButtonItemStyleBordered target:self action:@selector(button2Pressed:)] autorelease], [[[UIBarButtonItem alloc] initWithTitle:@"Button 3" style:UIBarButtonItemStyleBordered target:self action:@selector(button3Pressed:)] autorelease], [[[UIBarButtonItem alloc] initWithCustomView: [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1x1Transparent.png"]] autorelease]] autorelease], [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease], nil]]; 
+5
source

The smart solution is to simply add an instance of UIBarButtonItem with a simple style and disable it.

+3
source

Source: https://habr.com/ru/post/1341252/


All Articles