gpt4 book ai didi

ios - UIButton 在 UIScrollView 中不起作用

转载 作者:IT王子 更新时间:2023-10-29 08:08:47 25 4
gpt4 key购买 nike

我的观点结构:

UITableView
UITableViewCell
UIScrollView
CustomView
UIButton

问题是当我触摸 UIButton 时它不起作用。我用代码创建它:

btn = [[UIButton alloc] init];
[btn setImage:image forState:UIControlStateNormal];
[btn addTarget:self action:@selector(tileTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
btn.layer.zPosition = 1;
[self addSubview:btn];

我还添加了这个:

scroll.delaysContentTouches = NO;
scroll.canCancelContentTouches = NO;

但是我的按钮无论如何都不起作用。我无法取消 ContentTouches 或为 UITableView 设置延迟,因为如果我设置它,UITableView 将停止垂直滚动。

感谢您的帮助!

最佳答案

创建一个 UIScrollview 的子类

- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
return NO;
}

如果您没有收到该消息,请设置:

scrollView.delaysContentTouches = NO;

问题是由于 touchesShouldCancelInContentView 的默认行为方式,只有当 subview 是 UIControl 时它才返回 NO,但您的按钮隐藏在 CustomView 中,而 CustomView 不是。

关于ios - UIButton 在 UIScrollView 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16649639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com