【问题标题】:Overlay button not clickable/pressable.覆盖按钮不可点击/不可按下。
【发布时间】:2012-07-25 02:53:37
【问题描述】:

我在 UIToolBar 叠加层上叠加了一个完成按钮。完成按钮出现在我的工具栏上,但不可点击。事实上,当我触摸它时,它没有任何变化。显然 doneButton 没有接收到动作。我的问题是为什么以及如何纠正这个问题?我应该用什么替换我的错误代码?

这是我设置叠加层的地方。

- (UIView*)CommomOverlay  {
    //Main overlay(not pertinent in this question)
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,420)];
    UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,420)];
    [FrameImg setImage:[UIImage imageNamed:@"newGraphicOverlay.png"]];

    //Toolbar overlay
    UIToolbar *myToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 428, 320, 50)];
    [myToolBar setBarStyle:UIBarStyleBlack];

    //Done button overlay
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] 
                                   initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                        target:self
                                                        action:@selector(doneButtonPressed)];

    [myToolBar setItems:[NSArray arrayWithObjects: doneButton, nil] animated:YES];

    [FrameImg addSubview:myToolBar];
    [view addSubview:FrameImg];
    return view;
}

这是我使用的 doneButton 按下方法。单击完成后,视图应该恢复到另一个屏幕,其中 .h/.m 位于 SecondViewController 的名称中。

-(void)doneButtonPressed {

    SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil
    bundle:nil];
    screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:screen animated:YES];
    [screen release];
}

在我看来一切都是完美的,但不用说它不是。我知道这似乎是一个常见问题,但我没有搜索到关于按钮无法在叠加层上运行的问题。请不要只讨论更正部分,还要讨论为什么部分。

【问题讨论】:

  • 您是否看过这个答案以进行更正以及为什么? stackoverflow.com/a/2476310/774691 我问是因为我不知道您是否尝试以允许设置toobarItems 的方式进行上述操作。

标签: ios overlay uitoolbar


【解决方案1】:

您可以通过执行以下操作来检查这件事是否有效..

FrameImg.userInteractionEnabled = YES;

不确定这是否有帮助。

【讨论】:

  • 首先,我要在哪里添加这个?
  • UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,420)]; [FrameImg setImage:[UIImage imageNamed:@"newGraphicOverlay.png"]]; FrameImg.userInteractionEnabled = YES;
  • 这次尝试不走运。我不明白的是为什么声明涉及FrameImg?我的 doneButton 需要确认用户交互。它根本不承认我给了它一个动作命令。
  • 我要求这个尝试,因为 myToolbar 是 FrameImg 的子视图。所以我认为这可能会阻止工具栏项目获取事件。
猜你喜欢
  • 2015-10-05
  • 1970-01-01
  • 1970-01-01
  • 2018-01-05
  • 2017-11-01
  • 2012-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多