UIScrollView内部的UIButton不是随时触发的。请帮助解决此问题。
// Add a button
UIButton *btn1 = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
btn1.frame = CGRectMake(0, 0, 26, 18);
btn1.bounds = CGRectMake(0, 0, 30.0, 30.0);
[btn1 addTarget:self action:@selector(buttonClick1:)
forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:btn1];
- (void)buttonClick1:(id)sender {
int dd = 4;
}
发布于 2013-04-08 18:04:19
您必须设置视图的内容大小。它必须大于或等于scrollView的内容大小。
因为视图的默认大小是320 x 480 (3.5“视网膜)和320 x 568 (4”视网膜)。因此,将视图高度增加为:
self.view.frame=CGRectMake(0, 0, 320, 700);
然后,将此作为scrollView的子视图添加,您将找到解决方案。
发布于 2017-01-31 04:13:02
我遇到了同样的问题,我所做的不是将按钮添加到容器视图中,而是将其添加到容器视图顶部的滚动视图中:
scrollView.insertSubview(buttonA, aboveSubview: containerView)
我的结构是:
-View
--ScrollView
---ContainerView
我希望这对任何人都有帮助。
发布于 2019-12-02 02:11:28
你在这里列出的我都试过了。也是在整个互联网上。但是我的纽扣还是不能操作。
最后,唯一对我有帮助的是。我还能把"isUserInteractionEnabled“放在卷轴视图上
那么,我是如何修复它的:
1)转到故事板
2) ContentView和MainView互通
3)并选择宽度/高度相等
顺便说一句,我也在代码中设置了视图(对于我来说,没有prev步骤就不能工作)。
// sizes
let width = self.view.safeAreaLayoutGuide.layoutFrame.width
mainView.frame = CGRect(x: 0 , y: 0, width: width, height: self.view.safeAreaLayoutGuide.layoutFrame.height)
contentView.frame = CGRect(x: 0 , y: 0, width: width, height: 1000)
scrollView.frame = CGRect(x: 0 , y: 0, width: width, height: mainView.frame.height)
// constraints:
contentView.widthAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.widthAnchor).isActive = true
scrollView.widthAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.widthAnchor).isActive = true
当然,这不是像“只需按两个按钮就能解决你的问题”那样的解决方案。主要原因是与约束有关&在我的例子中是内容大小。仅供参考,也许这会对某些人有帮助。
https://stackoverflow.com/questions/3132147
复制相似问题