Why is the UIButton exclusiveTouch property not set by default?

I am sure there are many reasons why someone would like several buttons to take strokes at the same time. However, most of us only need one button to press simultaneously (for navigation, so that it can be represented modally, to represent popover, presentation, etc.).

So why did Apple set the exclusiveTouch UIButton property to NO by default?

+7
source share
4 answers

A very old question, but IMO deserves clarification.

Despite the fact that the Apple application has very misleading methodological documentation, the β€œA” view with the exclusiveTouch setting will prevent other views from receiving events while A processes an event itself (for example, install the button with the exclusive Touch and place a finger on it, this will prevent the interaction of other views in the window, but interaction with them will follow the usual pattern after removing the finger from the exlusiveTouch element).

Another effect is to prevent the presentation of A events if any other presentation interacts (hold the button without the exclusive dialing pressed, and those with the exclusive Touch will also not be able to receive events).

You can still set the button in your view to an exclusive check and interact with others, just not at the same time, as this simple UIViewController test will prove (as soon as the correct bindings in IB are set for both Outlets and Actions)

 #import "FTSViewController.h" @interface FTSViewController () - (IBAction)button1up:(id)sender; - (IBAction)button2up:(id)sender; - (IBAction)button1down:(id)sender; - (IBAction)button2down:(id)sender; @property (nonatomic, strong) IBOutlet UIButton *button1, *button2; @end @implementation FTSViewController - (IBAction)button1up:(id)sender { NSLog(@"Button1 up"); } - (IBAction)button2up:(id)sender { NSLog(@"Button2 up"); } - (IBAction)button1down:(id)sender { NSLog(@"Button1 down"); } - (IBAction)button2down:(id)sender { NSLog(@"Button2 down"); } - (void)viewDidLoad { [super viewDidLoad]; // Guarantees that button 1 will not receive events *unless* it the only receiver, as well as // preventing other views in the hierarchy from receiving touches *as long as button1 is receiving events* // IT DOESN'T PREVENT button2 from being pressed as long as no event is being intercepted by button1!!! self.button1.exclusiveTouch = YES; // This is the default. Set for clarity only self.button2.exclusiveTouch = NO; } @end 

In light of this, the only good reason why IMHO for Apple does not set exclusiveTouch for YES for each subclass of UIView is that it would make the implementation of complex gestures real PITA, including probably some of the gestures that we are already used to in composite UIView subclasses (e.g. UIWebView), since setting selected views to exclusiveTouch = NO (e.g. a button) is faster than doing recursive exclusive Touch = YES, basically for everything to enable multitouch.

The disadvantage of this is that in many cases, the counter intuitive behavior of UIButtons and UITableViewCells (among others ...) can lead to strange errors and make testing more complicated (how did this happen to me, how ... 10 minutes ago? :( )

Hope this helps

+8
source

The UIView exclusiveTouch property means that the view (button) is ONLY in this window that you can interact with if it is set to YES . As stated in the docs: setting this property to YES causes the receiver to block the delivery of touch events to other views in the same window. The default value of this property is NO.

Therefore, this is the usual behavior in which you can have several buttons or controls / interaction views in the window and want exclusiveTouch set to NO .

If you set this class to YES for any subclass of UIView in the window, you cannot interact with anything else in this window until this property is set to YES . This means that if you initialize a button using exclusiveTouch = YES , but also have a table view or other button or scroll view or any other interaction-based view, it will not respond to any touches.

-one
source

exclusiveTouch simply means that any view under your UIButton will not receive touch events.

The default value is No, because you usually want the view below it to receive these events. For example, if you have a UIButton on top of a scroll and the user wants to scroll. You want scrollView to scroll even if they start with a finger on UIButton.

-one
source

I just read the release notes for iOS 5, and from this version, the default Touch exclusive value will be set to YES. Therefore, just keep in mind that it will change with the new version of iOS.

-one
source

All Articles