pointInside:withEvent: called when typing on keyboard on iOS8

droussel

I've stumbled upon this issue and I'm not sure what would be the best way to deal with it. The issue is very easy to reproduce and I've put a simple demo project on GitHub for demonstration, but here's the gist of it.

Let's say I have an iPad app with a UITextField in it's main view. Below it is a small UIView subclass which implements pointInside:withEvent:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    BOOL inside = CGRectContainsPoint(self.bounds, point);
    NSLog(@"pointInside Called");
    return inside;
}

Running the app, the pointInside method gets called if I tap anywhere on the screen BUT the keyboard; typing on the keyboard does not trigger the pointInside method.

While leaving the keyboard up, I then send the app in the background and then come back to the app. Now, every time I type on the keyboard, the pointInside method gets called! The only way I found to 'fix' the issue is to set the UITextEffectsWindow as keyAndVisible; but this is not really viable as it could introduce other side effects.

Any idea how to deal with this? My problem is that we were using this method in our app to dismiss a popup when the user taps outside of it. But there is a UITextField in the popup and we obviously don't want to discard the popup when the user starts typing in it...

Thanks in advance

droussel

I finally went with a UITapGestureRecognizer added to the UIWindow. The custom view adds it upon moving to a new window and removes it when being deallocated; works fine and solves my problem :

@property (strong, nonatomic) UITapGestureRecognizer *outsideTapRecognizer;

- (void)willMoveToWindow:(UIWindow *)newWindow
{
    if(self.outsideTapRecognizer){
        [self.window removeGestureRecognizer:self.outsideTapRecognizer];
    }

    self.outsideTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOutside:)];
    [newWindow addGestureRecognizer:self.outsideTapRecognizer];
}

- (void)tapOutside:(UIGestureRecognizer *)gestureRecognizer {
    BOOL inside = CGRectContainsPoint(self.bounds, [gestureRecognizer locationInView:self]);
    if (!inside) {
        [self removeFromSuperview];
    }
}

- (void)dealloc
{
    [self.window removeGestureRecognizer:self.outsideTapRecognizer];
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Keyboard dismissing when setState is called

분류에서Dev

Typing || on my keyboard

분류에서Dev

iOS8 Keyboard Extension get current context

분류에서Dev

How to get simulate Keyboard typing using python

분류에서Dev

iOS8 Custom Keyboard Settings.bundle이 표시되지 않음

분류에서Dev

iOS8 Custom Keyboard Settings.bundle이 표시되지 않음

분류에서Dev

iOS 8 custom keyboard on device

분류에서Dev

Keyboard does not open when display alertview with Textfield in ios 5.0

분류에서Dev

My app unexpectedly asks for notification permission when build with xcode6 for ios8

분류에서Dev

hitTest : WithEvent 및 Subviews

분류에서Dev

iOS LayoutSubviews being called multiple times when a subview resizes

분류에서Dev

Feedback when typing password at a sudo prompt

분류에서Dev

When is toString() method called

분류에서Dev

GLUT keyboard and mouse func just won't get called

분류에서Dev

Can't dismiss keyboard, UITextField delegate being called OK

분류에서Dev

udev rule to auto load keyboard layout when usb keyboard plugged in

분류에서Dev

Remove Notification when addAction called?

분류에서Dev

OnNavigatedFrom is not called when the app is suspended

분류에서Dev

OnPropertyChanged not fired when SetProperty is called

분류에서Dev

iOS8의 ModalViewController

분류에서Dev

Segue is not performed iOS8

분류에서Dev

Issue with presenting custom size ViewController modally in ios 8 with keyboard

분류에서Dev

iOS 8 keyboard extension - able to use Apple default keyboard template xib?

분류에서Dev

Hide keyboard when navigation bar is touched

분류에서Dev

Android avoid soft keyboard when startup

분류에서Dev

Bring up keyboard when clicking on EditText

분류에서Dev

keyboard layout returning to default when using kvm

분류에서Dev

Swift hitTest : point withEvent to detect subview

분류에서Dev

How to work with hardware keyboard in iOS?

Related 관련 기사

  1. 1

    Keyboard dismissing when setState is called

  2. 2

    Typing || on my keyboard

  3. 3

    iOS8 Keyboard Extension get current context

  4. 4

    How to get simulate Keyboard typing using python

  5. 5

    iOS8 Custom Keyboard Settings.bundle이 표시되지 않음

  6. 6

    iOS8 Custom Keyboard Settings.bundle이 표시되지 않음

  7. 7

    iOS 8 custom keyboard on device

  8. 8

    Keyboard does not open when display alertview with Textfield in ios 5.0

  9. 9

    My app unexpectedly asks for notification permission when build with xcode6 for ios8

  10. 10

    hitTest : WithEvent 및 Subviews

  11. 11

    iOS LayoutSubviews being called multiple times when a subview resizes

  12. 12

    Feedback when typing password at a sudo prompt

  13. 13

    When is toString() method called

  14. 14

    GLUT keyboard and mouse func just won't get called

  15. 15

    Can't dismiss keyboard, UITextField delegate being called OK

  16. 16

    udev rule to auto load keyboard layout when usb keyboard plugged in

  17. 17

    Remove Notification when addAction called?

  18. 18

    OnNavigatedFrom is not called when the app is suspended

  19. 19

    OnPropertyChanged not fired when SetProperty is called

  20. 20

    iOS8의 ModalViewController

  21. 21

    Segue is not performed iOS8

  22. 22

    Issue with presenting custom size ViewController modally in ios 8 with keyboard

  23. 23

    iOS 8 keyboard extension - able to use Apple default keyboard template xib?

  24. 24

    Hide keyboard when navigation bar is touched

  25. 25

    Android avoid soft keyboard when startup

  26. 26

    Bring up keyboard when clicking on EditText

  27. 27

    keyboard layout returning to default when using kvm

  28. 28

    Swift hitTest : point withEvent to detect subview

  29. 29

    How to work with hardware keyboard in iOS?

뜨겁다태그

보관