And*_*nov 2 cocoa-touch touch uibutton uiview ios
我有两个UIButtons我正在以编程方式创建并设置目标.如果我将这些按钮添加到主视图中,一切都可以很好地工作.但是,当我首先添加到子视图并将此子视图添加到主视图时,触摸事件不起作用.我猜这些按钮被掩盖了.
如何在将这些按钮保留在子视图中的同时将其打开?
这是我的代码:
// Create button panel here
UIImage *buttonPanel = [UIImage imageNamed:@"left_button_background"];
UIImageView *buttonPanelView = [[UIImageView alloc] initWithImage:buttonPanel];
[buttonPanelView setFrame:CGRectMake(20, 186, 363, 345)];
// Populate the panel with buttons
UIButton *cmsButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 351, 142)];
[cmsButton setImage:[UIImage imageNamed:@"BTN_MATLIB"] forState:UIControlStateNormal];
[cmsButton addTarget:self action:@selector(loadCMS) forControlEvents:UIControlEventTouchDown];
[buttonPanelView addSubview:cmsButton];
[self setCms:cmsButton];
UIButton *calcButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 196, 351, 142)];
[calcButton setImage:[UIImage imageNamed:@"BTN_MORE_RESOURCES"] forState:UIControlStateNormal];
[calcButton addTarget:self action:@selector(loadCalc) forControlEvents:UIControlEventTouchDown];
[buttonPanelView addSubview:calcButton];
[self setCalc:calc];
[[self view] addSubview:buttonPanelView];
Run Code Online (Sandbox Code Playgroud)
rob*_*off 12
默认情况下,图像视图未启用用户交互,这意味着它们的子视图都不能接收用户交互.
buttonPanelView.userInteractionEnabled = YES;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5029 次 |
| 最近记录: |