叠加按钮不可点击/可按下。

时间:2012-07-25 02:53:38

标签: ios overlay uitoolbar

我在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;
}

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

-(void)doneButtonPressed {

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

对我来说,一切看起来都很完美,但不用说它不是。我知道这似乎是一个经常被问到的问题,但我搜索的内容并不是关于按钮在覆盖上运行的功能。请不仅要讨论修正部分,还要讨论为什么部分。

1 个答案:

答案 0 :(得分:0)

你可以通过以下方式检查这件事是否有效..

FrameImg.userInteractionEnabled = YES;

我不确定这是否会有所帮助。