0

Hi I have a UIView who's alpha is 0.7 and below it are some UITextFields. I don't want it to call touches events while keeping touches events. I tried using

[lightBoxView setUserInteractionEnabled:NO];

But now the UITextFields can become active or first responder. How can I disable it from calling touch events as well as not passing touches to others?

Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Hassy
  • 5,068
  • 5
  • 38
  • 63
  • you can use Controller editing property i.e. self.editing = NO; in touch methods – Anuj Nov 26 '13 at 07:26
  • Do `[lightBoxView setUserInteractionEnabled:YES];`, because if you set it **NO** it ignores the touch on that view. – TheTiger Nov 26 '13 at 07:34

2 Answers2

1

You can remove those control from tough gesture delegate method.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isKindOfClass:[UITextFiled class]])
    {
        return NO;
    }
    else
    {
        return YES;
    }
}
Baby Groot
  • 4,637
  • 39
  • 52
  • 71
1

You also need to set the userInteractionEnabled = NO for all the subviews as well.

Try this,

[[lightBoxView subviews] makeObjectsPerformSelector:@selector(setUserInteractionEnabled:)
                          withObject:[NSNumber numberWithBool:NO]];

This will call setUserInteractionEnabled: on all direct subviews of lightBoxView and set it to NO. For a more complex subview hierarchy you will have to recursively loop through all the child views and disable the user interaction on each one. For this you can write a recursive method in a UIView category. For more details about this category method take a look at this answer.

Hope that helps!

Community
  • 1
  • 1
Amar
  • 13,202
  • 7
  • 53
  • 71
  • The Subviews are not part of lightBoxView – Hassy Nov 26 '13 at 08:32
  • lightBoxView has no subviews instead subview are on view on which lightBoxView is also a subview – Hassy Nov 26 '13 at 08:34
  • 1
    @ghazi_jaffary You can use same code on that view then. Anyways what you are trying to achieve is disable interaction on all subviews of that view. This code with modifications to access required views subview should work. – Amar Nov 26 '13 at 08:35