0

我在 tableview 之上创建 UIView,其中将有一个 imageview,最重要的是会有几个按钮。当点击更改按钮(导航栏)时,将显示此 UiView。我已经以编程方式添加了所有内容。但我无法点击 UIView 中存在的按钮

-(IBAction)changeViewController:(id)sender {
    if(!isViewShowing){
        NSLog(@"show Imageview");
        viewContainer = [[UIView alloc] initWithFrame: CGRectMake ( 276, 2, 40, 230)];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 230)];
        [imageView setImage:[UIImage imageNamed:@"bar.png"]];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(buttonPressedAction:)forControlEvents:UIControlEventTouchUpInside];
        //[button setTitle:@"Show View" forState:UIControlStateNormal];
        button.frame = CGRectMake(0.0, 25.0, 36.0, 36.0);
        [button setBackgroundImage:[UIImage imageNamed:@"OLFB icon.png"] forState:UIControlStateNormal];

        [imageView addSubview:button];
        //[imageView release];
        [viewContainer addSubview: imageView];

        [self.view addSubview:viewContainer];
        [self.view bringSubviewToFront:button];
        //[polygonView release];
        isViewShowing=YES;
    }
    else 
    {
        NSLog(@"view not showing");
        [viewContainer removeFromSuperview];
        isViewShowing=NO;
    }

}
4

2 回答 2

3

userInteractionEnabledin的属性默认UIImageView设置为.. 只需 make就可以了。NOimageView.userInteractionEnabled = YES;

于 2012-06-19T08:20:22.990 回答
0

我的天啊。只需将imageView的userInteractionEnabled设置为YES,然后imageView中添加的按钮就会响应点击事件。

imageView.userInteractionEnabled = YES;
于 2012-06-19T08:48:15.753 回答