Iphone 按钮对触摸不响应

Iphone 按钮对触摸不响应,iphone,uiimageview,uibutton,Iphone,Uiimageview,Uibutton,在我的应用程序中,我在UIImageview中添加了UIImageview,并在UIImageview中添加了UIButton。该按钮不对触摸事件做出响应,并且不会调用动作选择器。为什么?因为默认情况下,UIImageView的userInteractionEnabled属性设置为NO。将其设置为YES,它就会工作。确保您的按钮已连接iAction。然后检查它是否启用了用户交互。尝试此方法解决此问题 UIIMageView *image; image.userInteractionEnabled

在我的应用程序中,我在
UIImageview
中添加了
UIImageview
,并在
UIImageview
中添加了
UIButton
。该按钮不对触摸事件做出响应,并且不会调用动作选择器。为什么?

因为默认情况下,
UIImageView
userInteractionEnabled
属性设置为
NO
。将其设置为
YES
,它就会工作。

确保您的按钮已连接iAction。然后检查它是否启用了用户交互。

尝试此方法解决此问题

UIIMageView *image;
image.userInteractionEnabled=YES;
希望这对任何人都有帮助


Minu

首先添加imageview,然后添加按钮,然后按钮像下面的代码一样正常工作

 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 

顺便说一句,这是UIKit中另一个无脑的不一致性。这是故意的,但这比好事更令人困惑。