我的按钮有一个奇怪的行为,我添加到滚动视图。
for (UIView *subview in self.scrollView.subviews) {
[subview removeFromSuperview];
}
//Create and place info Button(s)
for (int i = 0; i < BigPictures.count; i++) {
UIButton *infoButton = [[UIButton alloc] initWithFrame:CGRectMake(scrollView.frame.size.width*(i+1) - 29 - 5 - 10, scrollView.frame.size.height - 29 - 5, 29, 29)];
[infoButton addTarget:self action:@selector(flip) forControlEvents:(UIControlEvents)UIControlEventTouchUpInside];
//[infoButton setEnabled:YES];
//[infoButton setUserInteractionEnabled:YES];
[self.scrollView addSubview:[FrontViews objectAtIndex:i]];
[infoButton setBackgroundImage:[UIImage imageNamed:@"btn_image-info.png"] forState:UIControlStateNormal];
[scrollView addSubview:infoButton];
BigPictures包含我想在scrollview中显示的所有图像。 现在到了奇怪的事情。如果BigPictures包含1个图像,则调用动作(翻转)。一旦[BigPictures count]&gt; 1然后第一个图像上的按钮没有执行动作,而是所有其他按钮(第2-n页)。那怎么可能呢?
即使我使用for (int i = 0; i < BigPictures.count; i++)
更改for (int i = 0; i < 1; i++)
,按钮也会正常工作。
那我错过了什么?已经尝试过像
这样的东西scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = NO;
但后者禁止滚动滚动视图。
编辑:
我尝试将其他按钮放在不同的位置,但没有一个按钮在第一页上工作(如果页面&gt; 1)。还试图放置一个GestureRecognizer。这有效,但if ([touch.view isKindOfClass:[UIButton class]])
未检测到下方的按钮。所有在scrollview的其他页面上都可以正常工作。真的很奇怪。
答案 0 :(得分:0)
完成了重建,现在可行了。真奇怪,因为我使用了完全相同的代码。