gpt4 book ai didi

iphone - UIScrollView 内的 UIButton 不会在点击时触发

转载 作者:行者123 更新时间:2023-12-03 18:16:41 25 4
gpt4 key购买 nike

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;
}

最佳答案

我发现了这个东西:

But the scrollview will block the touches from the button unless you set userInteractionEnabled and exclusiveTouch properties to NO on the scrollview. But that would defeat the purpose of having a scrollview inside a button I think.

(参见Can we put a UIButton in a UIScrollView and vice versa in iPhone)

但是怎么做呢?

假设你有一个 UIScrollView *sv ...然后

sv.userInteractionEnabled = YES;
sv.exclusiveTouch = YES;

我还要补充

sv.canCancelContentTouches = YES;
sv.delaysContentTouches = YES;

关于iphone - UIScrollView 内的 UIButton 不会在点击时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3132147/

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