我有一个 ScrollView ,它有一个 ImageView , ImageView 作为 subview , ImageView 有一个 UIButton
作为它的 subview 之一。问题是,我无法点击按钮。我可以看到按钮,但无法点击它。
谁能告诉我我搞砸了什么?任何帮助是极大的赞赏!谢谢!
代码如下:
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img.jpg"]];
scrollView.delegate = self;
self.view = scrollView;
// add invisible buttons
[self addInvisibleButtons];
[scrollView addSubview:imageView];
addInvisibleButtons
具有以下代码:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonHandler) forControlEvents:UIControlEventAllEvents];
[button setTitle:@"point" forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
[self.imageView addSubview:button];
最佳答案
UIImageView
默认将 userInteractionEnabled
设置为 NO
/false
。
您正在将按钮作为 subview 添加到 ImageView 中。您应该将其设置为 YES
/true
。
关于ios - UIImageView 内的 UIButton 不响应点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6164357/