0
votes

I have UIView like this.

enter image description here

I need to put my finger on that view and drag along on those button just like playing piano. Problem is that if initial touch point is on the main view and if I drag along, touches event for main view is triggered and my buttons touch events are not triggered.

As a result, I put this.

[self setUserInteractionEnabled:NO];

Problem is that it has disabled my buttons and other subviews. I want to totally ignore touch event, user interaction from main view but allow for all those subview. How shall I do?

2
All subviews added on superview would not be clickable if you disable superview's user interaction. So if you want to make the keyboard view as clickable and main view as not clickable, then you must not add the key board on the main view, rather you can add it on window, then it will respond to click event even if you disable the user interaction of main view of that screen. Hope it helps... - Janmenjaya
But I can't add to window in keyboard extension. :( - Khant Thu Linn
Ok, then can you add other subviews that you need, in a separate View and disable that view's user interaction. I mean to say add a view and keyboard view to main view then add other stuffs to that view and disable that view's user interaction, The main concern is don't disable the superview's user interaction of keyboard view. - Janmenjaya
You can set up a notification event for keyboardWillShow and inside the target function set [self setUserInteractionEnabled:NO]; for the superView and when keyboardWillHide notification re-enable it. Hope this helps. - Md. Ibrahim Hassan
@Janmenjaya It is not okay. The moment when I disable particular UIView, all subview (for my case, it is button )in that view is disabled. Adding another subview is same as original plan though. - Khant Thu Linn

2 Answers

0
votes

You can set up a notification event for keyboardWillShow and inside the target function set [self setUserInteractionEnabled:NO]; for the superView and when keyboardWillHide notification re-enable it. For hiding the keyboard you could use the GO Button or to dismiss the keyboard add an invisible UIButton to the remaining part of the Screen when the keyboardWillShow event is called and use it to resign first responder.

Hope this helps.

0
votes

You should create a subclass of UIView for your main view. It should overwrite - hitTest:withEvent: returning always the nearest view for a key.

An alternative solution without inheritance is giving all keys an invisible border such that their views cover the complete main view but never returning the main view.