0

I have many SubViews in my UIView, and many of them have UIButtons in them. One of the subviews- _bottomView (Coordinates- (0,519,320,49)) has an error. It does not recognise the click events on the buttons placed inside it.

I tried placing a UIButton covering the entire _bottomView and the click event from that Button (testButton) is not being recognised either.

I tried adding a tapRecogniser to the code and the tap from every point, EXCEPT the points within the _bottomView are recognised. TapRecogniser Code below

UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
    [self.view addGestureRecognizer:gr];
    _bottomView.userInteractionEnabled=true;


-(void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
    CGPoint p = [gestureRecognizer locationInView:self.view];
        NSLog(@"got a tap in the region i care about");
}

I tried [self.view addSubview:_bottomView]; and that didn't help either. What could be the issue?

ViewController

Screen

Sidharth J Dev
  • 927
  • 1
  • 6
  • 25
  • Do you want the button to handle the tap or the UITapGestureRecognizer ? – Yan Nov 05 '15 at 05:40
  • I want the button to handle the tap. But I figured, that the View inside which the button exists must atleast handle the tapGesturerecognizer, right? – Sidharth J Dev Nov 05 '15 at 05:41
  • Maybe you are looking for this(http://stackoverflow.com/questions/3344341/uibutton-inside-a-view-that-has-a-uitapgesturerecognizer). Read this document(https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/event_delivery_responder_chain/event_delivery_responder_chain.html#//apple_ref/doc/uid/TP40009541-CH4-SW3) for clarification. – Rahul Wakade Nov 05 '15 at 05:48
  • The button should handle it's own taps unless you need both the button and the view handle separate taps as @RahulWakade pointed out. – Yan Nov 05 '15 at 05:50
  • @RahulWakade no that article doesn't help. The questioner has UITapGestureRecognizer working, in his case. I don't NEED tapRecognizer in my app. I just put that in to check if Tap is being detected in that particular view. – Sidharth J Dev Nov 05 '15 at 05:50
  • Can you set clipSubview to yes to your `_bottomView` and check that? – Vijay Nov 05 '15 at 05:51
  • @Yan Button is NOT recognising its own taps, thats why I put in a recogniser, which proved that the view in which the button resides, itself is not detecting taps – Sidharth J Dev Nov 05 '15 at 05:51
  • Are you creating buttons programmatically or in the storyboards? If programmatically post that code if you can – Yan Nov 05 '15 at 05:53
  • @Yan in the storyboard. – Sidharth J Dev Nov 05 '15 at 05:53
  • @Vijay how do I clip subview? what is the code? – Sidharth J Dev Nov 05 '15 at 05:54
  • Just want to make sure if you setting up the action function and is it connected to the button? – Yan Nov 05 '15 at 05:55
  • yes, I have them all set up – Sidharth J Dev Nov 05 '15 at 05:56
  • @SidharthJDev, Check this on your _bottomView in XIB or storyboard. http://i.stack.imgur.com/w2V0T.png – Vijay Nov 05 '15 at 05:56
  • @Vijay tried that too. No change – Sidharth J Dev Nov 05 '15 at 05:58
  • @SidharthJDev Can you show your screen? – Vijay Nov 05 '15 at 05:59
  • Added the screens.. Circled out the buttons, that don't recognise the tap. The red view in Simulator screen is the view in question. Is everything understandable? – Sidharth J Dev Nov 05 '15 at 06:06
  • @Vijay can you understand everything from the screens i posted? – Sidharth J Dev Nov 05 '15 at 06:31
  • @SidharthJDev Yes. Can you check debug view hierarchy in xcode that is there any view overrides on bottomview? – Vijay Nov 05 '15 at 07:06
  • @SidharthJDev, Move your button to top in your view. He XIB hierarchy should be like this Button, ImageView, Label.. And remove your gesture and try.. – Vijay Nov 05 '15 at 07:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/94284/discussion-between-sidharth-j-dev-and-vijay). – Sidharth J Dev Nov 05 '15 at 07:12

2 Answers2

0

If your view is not receiving touches

  1. Make sure that your UIView has userInteractionEnabled set to YES
  2. Make sure that the view is within the bounds of its superview, and the superview is within the bounds of window.You can print the frames of views using NSLog(@"%@",NSStringFromCGRect(view.frame));
Saif
  • 2,678
  • 2
  • 22
  • 38
0

Nothing helped. I had to delete the entire View Controller and redo the whole thing. That obviously solved the problem.

Sidharth J Dev
  • 927
  • 1
  • 6
  • 25