8

I am launching a simple UIView with a textField - let's call it orderSetNameView - upon a button tap. I wish to make this view modal, but without using a

[UIViewController presentModalViewContoller:animated:].

It seems I could simply set textInputView.exclusiveTouch = YES to achieve that.

Apple documentation says about exclusiveTouch:

A Boolean value indicating whether the receiver handles touch events exclusively. If YES, the receiver blocks other views in the same window from receiving touch events; otherwise, it does not. The default value is NO.

I assume "same window" means same UIWindow, of which I have only one.

The problem is that when I instantiate my orderSetNameView, add it as a subview, and set exclusiveTouch = YES, touch events happen in all other views of my app, i.e., touch events in other views are not blocked as expected.

    // ....

    [self.view addSubview:self.orderSetNameView];
    [self.orderSetNameView openWithAnimationForAnimationStyle:kMK_AnimationStyleScaleFromCenter];
}

// Set as modal
self.orderSetNameView.exclusiveTouch = YES;

Shouldn't orderSetNameView block touch events in all other views? What am I missing?

user987339
  • 10,519
  • 8
  • 40
  • 45
seeker12
  • 731
  • 2
  • 8
  • 20
  • In the last paragraph before the code snippet, "textInputView" should read "orderSetNameView". sorry. – seeker12 Oct 15 '10 at 23:23
  • I should probably add that I'm building for Base SDK iOS 4.2 and iOS Deployment Target iOS 3.2 (for iPad). – seeker12 Oct 16 '10 at 23:46

2 Answers2

14

From Apple developer forums:

exclusiveTouch only prevents touches in other views during the time in which there's an active touch in the exclusive touch view. That is, if you put a finger down in an exclusive touch view touches won't start in other views until you lift the first finger. It does not prevent touches from starting in other views if there are currently no touches in the exclusiveTouch view.

To truly make this view the only thing on screen that can receive touches you'd need to either add another view over top of everything else to catch the rest of the touches, or subclass a view somewhere in your hierarchy (or your UIWindow itself) and override hitTest:withEvent: to always return your text view when it's visible, or to return nil for touches not in your text view.

seeker12
  • 731
  • 2
  • 8
  • 20
  • Thanks. Overriding hitTest:withEvent and returning self worked for me. I was trying to prevent the underlying table view from processing taps that occurred on a special, half-transparent UIView super-imposed upon it. – Alyoshak Apr 30 '12 at 23:45
0

Put this in AppDelegate or another file. Use this single time.

// Multi Touch Disable

UIView.appearance().isExclusiveTouch = true

UIButton.appearance().isExclusiveTouch = true

Urvish Modi
  • 1,118
  • 10
  • 11