【发布时间】:2013-08-26 14:53:34
【问题描述】:
我有一个UIScrollView,里面有按钮,当我试图按下按钮并滑动到一边时,UIScrollView 不会移动,但当我快速滑动时它会移动。我在按钮上使用UIControlEventTouchUpInside。这是我用来向滚动视图添加按钮的代码:
-(void) setScrollView:(int) numberOfViews {
for (int i = 0; i < numberOfViews; i++) {
CGFloat xOrigin = i * 40;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(scrollViewButtonClicked:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal];
button.frame = CGRectMake(xOrigin, 0, 40, 40);
button.tag = 1000+i;
button.backgroundColor = [self getColorForSound:self.sounds[i]];
[button setExclusiveTouch:YES];
[self.soundsScrollView addSubview:button];
}
}
即使用户按下按钮并尝试滚动,我怎样才能使 UIScrollView 滚动?
【问题讨论】:
-
您是否尝试过在按钮内部使用触摸拖动? touch up 可以触发当前动作,touch drag 可以做你想做的事情。
-
@calvinBhai 这不起作用。我需要将它滚动到一边,这无济于事。
-
@Amar 将 Cancelable Content Touches 设置为 yes 的答案对我不起作用。
-
@BlueGene 另外,请检查已接受答案的 cmets 中给出的链接。
标签: ios objective-c uiscrollview