问题描述
我的视图层次结构如下
MyViewController-> ScrollView(通过IB添加)-> ImageView(+缩放)--->在图像视图上添加了按钮(通过代码添加)
MyViewController --> ScrollView(added via IB) --> ImageView (+ zooming there) ---> button added on image View(added via code)
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map.png"]];
[scroll addSubview:imageView];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(660, 120, 40, 40);
[myButton setTitle:@"10" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(asiaPressed:) forControlEvents:UIControlEventTouchUpInside];
[myButton setEnabled:YES];
[imageView addSubview:myButton];
后来在视图控制器中,我将选择器定义为
later on in view controller, i defined selector as
-(void) asiaPressed:(id)sender{
NSLog(@"asiaPressed clicked");
}
但是它永远不会进入选择器.
But it is never going inside selector..
请帮助...我想这是一个非常基本的错误.
Pls help...i guess it is very basic error..
预先感谢
推荐答案
UIImageView的userInteractionEnabled属性默认情况下设置为NO,因此它(及其子视图)不接收触摸事件.您需要将该属性手动设置为是":
UIImageView has userInteractionEnabled property set to NO by default so it (and its subviews) does not receive touch events. You need to set that property to YES manually:
...
imageView.userInteractionEnabled = YES;
...
P.S.您也曾在问题标题中提到手势识别器,但是还没有发布任何代码-因此,如果它出现,它也可能会引起问题,但是问题很可能是我上面所描述的
P.S. You also mention gesture recognizer in question title, however have not posted any code with it - so if it present it may also cause the problems, but the problem is most likely is what I described above
这篇关于在单击手势时按钮单击不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!