这里是我的代码:IOS滚动视图无法点击
int i = 0;
self.userInteractionEnabled = YES;
self.exclusiveTouch = YES;
self.canCancelContentTouches = YES;
self.delaysContentTouches = YES;
self.translatesAutoresizingMaskIntoConstraints = YES;
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gototest)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[self addGestureRecognizer:tapGestureRecognizer];
for (NSString *message in self.messages) {
UILabel * label = [[UILabel alloc] initWithFrame:CGRectZero];
self.userInteractionEnabled = YES;
label.text = message;
label.tag = i;
CGSize size = [message sizeWithFont:label.font];
CGFloat width = size.width + kPADDING;
label.frame = CGRectMake(xPos, 0.0, width, self.frame.size.height);
[self addSubview:label];
i++;
xPos += width;
NSLog(@"%@",NSStringFromCGRect(label.frame));
}
self.messagesWidth = xPos;
self.contentSize = CGSizeMake(xPos, self.frame.size.height);
self.contentOffset = CGPointMake(-self.frame.size.width, 0.0);
}
-(void)gototest
{
NSLog(@"test %@",@"ccc ");
}
,然后选取框 - (无效)去{
if (!self.period) self.period = self.messagesWidth/100;
// so it always takes about the same (fudged, but reasonable) amount of time to scroll the whole array
[UIView animateWithDuration:self.period
delay:0.0
options:UIViewAnimationOptionCurveLinear |UIViewAnimationOptionRepeat
animations:^{
self.contentOffset = CGPointMake(self.messagesWidth, 0.0);
} completion:^(BOOL finished){}];
}
所以,我的目标是创建新闻选框,每个新闻都可以点击查看点击新的详细信息。
但UITapGestureRecognizer不工作,我不知道为什么。
请注意,自我是滚动视图,因为我的类从UIScrollView延伸。
所以,请帮我
我喜@Limon我不关心标签,我需要滚动视图点击。 – Houssam
你的意思是_clickable_?在iOS中没有像_click_这样的事件,我们正在这里使用_touches_和_gestures_。 – holex
hi @holex我喜欢触摸,所以当我触摸scrollview什么也没有发生 – Houssam