gpt4 book ai didi

iphone - UIScrollView 仅接受第二页上的触摸

转载 作者:行者123 更新时间:2023-11-29 04:57:24 24 4
gpt4 key购买 nike

我有一个子类UIScrollView,它将触摸传递到按钮(UIImageViews)。ScrollView 启用了分页功能,并以编程方式分布在 2 到 7 个页面之间。

但是,只有在显示第 2 页时才会识别触摸。滚动效果很好。

有什么想法吗?

这是我添加 ScrollView 时的设置:

lsScroll.pagingEnabled = YES;
[lsScroll setCanCancelContentTouches:NO];
lsScroll.frame = CGRectMake(0, 0, 320, 480);
lsScroll.bounds = CGRectMake(0, 0, 320, 480);
lsScroll.contentSize = CGSizeMake(lsScroll.bounds.size.width, lsScroll.bounds.size.height*maxSection);
[lsScroll setScrollEnabled:YES];
lsScroll.delaysContentTouches = YES;
lsScroll.delegate = self;
lsScroll.bounces = NO;
lsScroll.showsHorizontalScrollIndicator = NO;
lsScroll.showsVerticalScrollIndicator = NO;
lsScroll.clipsToBounds = YES;

(其中 maxSection)是定义页数的变量

然后以相同的方式添加部分页面:

section1View = [[UIImageView alloc] initWithFrame:self.view.frame];
section1View.bounds = CGRectMake(0, 0, 320, 480);
section1View.frame = CGRectMake(0, 0, 320, 480);
[section1View setBackgroundColor:[UIColor clearColor]];
[lsScroll addSubview:section1View];

section2View = [[UIView alloc] initWithFrame:self.view.frame];
section2View.bounds = CGRectMake(0, 480, 320, 480);
section2View.frame = CGRectMake(0, 480, 320, 480);
[section2View setBackgroundColor:[UIColor clearColor]];
[lsScroll addSubview:section2View];

section3View = [[UIImageView alloc] initWithFrame:self.view.frame];
section3View.bounds = CGRectMake(0, 960, 320, 480);
section3View.frame = CGRectMake(0, 960, 320, 480);
[section3View setBackgroundColor:[UIColor clearColor]];
[lsScroll addSubview:section3View];

更新:UIImageViews 然后被添加到section#View 中,这些是我正在检查触摸的对象。 section2View 上的 UIImageViews 注册触摸,但其他部分上的任何 UIImageViews 不注册触摸。

所有内容都显示正确,并且在正确的位置滚动有效,如果您位于第 2 页/第 2 部分,则触摸事件有效 - 但所有其他触摸都会失败。

非常感谢任何帮助。

更新:这是添加“UIImageViews”的代码。所以你可以看到我已经把这些都正确了。第一个是第 1 页上出现的“UIImageViw” - 未收到触摸,第二个是第 2 页上的“UIImageView” - 触摸有效。

ls1= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ls1.png"]];
ls1.center = (CGPoint){ 215, 65 };
ls1.transform = CGAffineTransformMakeScale(0.33,0.33);
[ls1 setUserInteractionEnabled: YES];
[section1View addSubview: ls1];

ls20= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ls20.png"]];
ls20.center = (CGPoint){ 215, 615 };
ls20.transform = CGAffineTransformMakeScale(0.33,0.33);
[ls20 setUserInteractionEnabled: YES];
[section2View addSubview: ls20];

这些代码行是使用电子表格中的宏创建的 - 所以我知道它们都是相同的并且都包含 setUserInteractionEnabled。

最佳答案

section2View 使用 UIView 创建,其余部分使用 UIImageView 创建。如果这些 ImageView 上的 userInteractionEnabled 为 NO,则它们的 subview 将不会接收触摸。

关于iphone - UIScrollView 仅接受第二页上的触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7693806/

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