【问题标题】:SubView not Considered a part of MainViewSubView 不被视为 MainView 的一部分
【发布时间】:2015-11-05 05:30:53
【问题描述】:

我的UIView 中有很多子视图,其中许多子视图中有UIButtons。其中一个子视图-_bottomView(坐标-(0,519,320,49))有错误。它无法识别放置在其中的按钮上的单击事件。

我尝试放置一个覆盖整个_bottomViewUIButton,并且该按钮(testButton)的点击事件也未被识别。

我尝试在代码中添加一个 tapRecogniser 并从每个点点击,除了 _bottomView 中的点被识别。点击下方的识别码

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

我试过[self.view addSubview:_bottomView];,但也没有用。可能是什么问题?

【问题讨论】:

  • 你想让按钮处理点击还是UITapGestureRecognizer?
  • 我想要按钮来处理水龙头。但我想,按钮所在的 View 必须至少处理 tapGesturerecognizer,对吧?
  • 也许你正在寻找这个(stackoverflow.com/questions/3344341/…)。请阅读此文档 (developer.apple.com/library/ios/documentation/EventHandling/…) 进行说明。
  • 该按钮应该处理它自己的点击,除非您需要按钮和视图处理单独的点击,正如@RahulWakade 指出的那样。
  • @RahulWakade 不,那篇文章没有帮助。在他的情况下,发问者有 UITapGestureRecognizer 工作。我的应用中不需要 tapRecognizer。我只是将其放入以检查是否在该特定视图中检测到 Tap。

标签: ios objective-c uiview uitapgesturerecognizer


【解决方案1】:

如果您的视图没有收到触摸

  1. 确保您的UIView 已将userInteractionEnabled 设置为YES
  2. 确保视图在其父视图的范围内,并且父视图在窗口的范围内。您可以使用NSLog(@"%@",NSStringFromCGRect(view.frame));打印视图的框架

【讨论】:

  • 如果您阅读代码并查看我发布的屏幕,您会发现我都检查了它们
  • bottomView 及其父视图以及[UIScreen mainScreen].bounds 的框架是什么?
  • superview-{{0, 0}, {320, 568}} bottomView-{{0, 519}, {320, 49}}
  • po mainScreen (origin = (x = 0, y = 0), size = (width = 320, height = 568)) (origin = (x = 0, y = 0), size = (宽度 = 320,高度 = 568))
【解决方案2】:

没有任何帮助。我不得不删除整个视图控制器并重做整个事情。这显然解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-31
    • 2015-02-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 2023-01-19
    • 2019-05-13
    • 1970-01-01
    相关资源
    最近更新 更多