我有一个子类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 中,这些是我正在检查的对象。UIImageViews
section2View 上的那些注册了触摸,但UIImageViews
其他部分上的任何都没有注册触摸。
一切都正确显示并且在正确的位置滚动工作,如果您在页面/第 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。