【发布时间】:2023-03-19 04:54:01
【问题描述】:
在我的应用程序中,我将UIImageview 添加到UIView,并将UIButton 添加到UIImageView。该按钮不响应触摸事件并且不调用动作选择器。为什么?
【问题讨论】:
标签: iphone uiimageview uibutton
在我的应用程序中,我将UIImageview 添加到UIView,并将UIButton 添加到UIImageView。该按钮不响应触摸事件并且不调用动作选择器。为什么?
【问题讨论】:
标签: iphone uiimageview uibutton
因为UIImageView 的userInteractionEnabled 属性默认设置为NO。将其设置为YES。
【讨论】:
UIIMageView *image;
image.userInteractionEnabled=YES;
【讨论】:
首先你添加图像视图然后添加按钮然后按钮像这段代码一样正常工作
UIView *AddView=[[UIView alloc]initWithFrame:CGRectMake(55, 0, 100, 100)];
UIImageView *imgview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
UIButton *btnRemove = [[UIButton alloc]init];
UIImage *btnImage = [UIImage imageNamed:@"close.png"];
[btnRemove setImage:btnImage forState:UIControlStateNormal];
[btnRemove addTarget:self
action:@selector(btnREmoveAction:)
forControlEvents:UIControlEventTouchUpInside];
btnRemove.frame = CGRectMake(0,0, 29, 29);
btnRemove.tag=indexStart;
[AddView addSubview:imgview]; // add the imageview
[AddView addSubview:btnRemove]; // add the button
【讨论】:
确保您已将 IBAction 附加到您的按钮。然后检查它是否启用了用户交互。
【讨论】: