0

I'm developing an iOS 8.1 app for an iPhone 5 in Objective-C using Xcode 6.1.

When a UITextView is clicked, I have an invisible UIControl view that pops up just above the keyboard, so that the user can swipe down from above the keyboard and dismiss the keyboard (and then move the UIControl out of view again). This is working fine. However, this UIControl view that pops up above the keyboard is covering another UITextView such that the covered text view cannot be tapped on. Every time I try to tap on the covered text view (which is visible because the UIControl is not opaque), nothing happens because the UIControl seems to just be taking the taps and not doing anything with them.

My question is, how do I make it so that the UIControl simply ignores taps (letting them go straight through so that the UITextView underneath can accept them), and yet accepts swipes (so that, when it is swiped downward, it can dismiss the keyboard and move out of view)?

I've tried several solutions but haven't found one that will work well for what I want.

Thanks!

Ethan G
  • 1,353
  • 2
  • 15
  • 31

3 Answers3

1

This question is similar to yours. Subclass your UIControl and override - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event and call its super variant to pass it up to its view.

Community
  • 1
  • 1
esh
  • 2,842
  • 5
  • 23
  • 39
  • Thanks for directing me to that question. I don't have time to test out the solution (and I've since moved on from this issue), but there haven't been any other answers as good as this so I'm going to mark this as accepted. – Ethan G Mar 26 '15 at 04:13
0

There is another way to do this. Change the main view of your UIViewController to a subclass of UIControl instead of UIView. Connect the following IBAction to the view in order to dismiss the keyboard when the background is tapped.

- (IBAction)backgroundTapped{

    [self.view endEditing:YES];

}

Apple Documentation - endEditing:

Michael
  • 6,561
  • 5
  • 38
  • 55
  • Will this still allow subviews of this main view to receive gestures? Won't it just take all the gestures for itself? – Ethan G Oct 22 '14 at 14:47
  • @EthanG It will not affect the `UITextField`, did you try it? – Michael Oct 22 '14 at 22:18
  • I haven't tried it yet because I still want a solution similar to what I described. I was just asking in case I do end up having to fall back to this alternative. Thanks. – Ethan G Oct 22 '14 at 23:30
0

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

Use this event. If tap gesture return no.

Yusuf terzi
  • 186
  • 7
  • Only problem is, I don't what the `UIControl` to just ignore the gesture. I want the gesture to pass through it to any views that are underneath. I don't think the suggestion you've provided here will do that, will it? – Ethan G Oct 22 '14 at 14:48