我有一个主视图控制器类,它包含一个UIScrollView和许多像卡片一样的子视图。
每张卡都是一个对象,并且它被一个UIButton所覆盖。我要检测UIButton上的点击,并禁止同时点击多张卡。
发布于 2013-05-14 12:24:29
我部分理解你的问题。看看以下内容是否有帮助:
在滚动视图中:
for (int i=0;i<array;i++)
{
UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(scrollWidth, 5,50,40)];
button.userInteractionEnabled=YES;
UITapGestureRecognizer *rcognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buttonSelcted:)];
[button addGestureRecognizer:rcognizer];
[scrollView addSubview:button];
scrollWidth=scrollWidth+80;
}在buttonSelected方法中,只需执行以下操作:
-(void)buttonSelected:(UITapGestureRecognizer *)recognizer
{
UIButton *selectedItem=(UIButton*)recognizer.view;
//do what you want with button
}发布于 2013-05-14 12:40:00
在你所有的按钮上setExclusiveTouch on。作为:
[button setExclusiveTouch:YES];有关它的更多详细信息,请参阅:
https://stackoverflow.com/questions/16535010
复制相似问题