简体   繁体   中英

SubView not Considered a part of MainView

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

屏幕

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));

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM