iOS 为什么添加在ScrollView上的button在我滑动ScrollView后, button的点击事件就失效了滑动时,控制台打印如下:
-[UIScrollView(UIScrollViewInternal) _offsetForRubberBandOffset:maxOffset:minOffset:range:] detected range=(newOffset - maxOffset), returning input unmodified
-[UIScrollView(UIScrollViewInternal) _offsetForRubberBandOffset:maxOffset:minOffset:range:] detected range=(newOffset - maxOffset), returning input unmodified
解决方案 »
- 这个用cocos2d-x怎么写?
- 在开发IOS组合控件关联.h.m代码文件程序就异常
- MKPinAnnotationView怎样添加一个蓝色的圆点,和其它大头针
- 求SIM卡中EF(CHV)和MF/DF/EF的头结构
- 定制的tableviewcell ( label + UITextField) 会导致程序crash
- <新人求教 >UITabviewCell修改数据后怎么同步修改数据源
- 求问ios升级APP步骤(刚学……)
- 有关饿了么首页动态cell的一个问题
- 各位大神,小弟毕业设计,要做基于ios8.0 集体照的人脸检测,跪求一个第三方呀
- ios 多线程多任务并发下载图片资源
- 企业包访问服务器plist文件的方法
- iOS App Store源码
CGFloat btnWidth = WIDTH/5;
_scrollView.backgroundColor = [UIColor lightGrayColor];
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.delegate = self;
_scrollView.contentSize = CGSizeMake(btnWidth*15, 0); [_scrollView setContentOffset:CGPointMake(0,0) animated:YES]; [self.view addSubview:_scrollView];代理方法:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{ if (scrollView == _scrollView) { // 如果此时滑动的是_scrollView,避免影响tableView的滑动
if (scrollView.contentOffset.y < 0) {
scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
}
if (scrollView.contentOffset.y > 0) {
scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
}
}
} for (int i = 0; i < 15; i++) {
UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(i*btnWidth, 0, btnWidth, 30)];
[btn setTitle:arr[i] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn.userInteractionEnabled = YES; btn.tag = i + btn_tag;
[_scrollView addSubview:btn];
}
写了代理方法后,button显示正常且禁止了上下滑动。但是在ScrollView滑动后,button点击不响应,且控制台有如下打印:
-[UIScrollView(UIScrollViewInternal) _offsetForRubberBandOffset:maxOffset:minOffset:range:] detected range=(newOffset - maxOffset), returning input unmodified
[super viewDidLoad];
_scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, 135)];
CGFloat btnWidth = WIDTH/5;
_scrollView.backgroundColor = [UIColor lightGrayColor];
_scrollView.showsVerticalScrollIndicator = YES;
_scrollView.delegate = self;
_scrollView.contentSize = CGSizeMake((btnWidth + 10)*15, 0);
[_scrollView setContentOffset:CGPointMake(0,0) animated:YES];
[self.view addSubview:_scrollView];
for (int i = 0; i < 15; i++) {
UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(i*(btnWidth + 10), 0, btnWidth, 30)];
[btn setTitle:[NSString stringWithFormat:@"%d",i+100] forState:UIControlStateNormal];
NSInteger armc4number = arc4random() %256;
btn.backgroundColor = [UIColor colorWithRed:armc4number/255.0 green:armc4number/255.0 blue:armc4number/255.0 alpha:1.0];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
btn.tag = i;
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn.userInteractionEnabled = YES;
[_scrollView addSubview:btn];
}
}
-(void)btnClicked:(UIButton *)sender{
UIButton *a = sender;
NSInteger count = a.tag;
NSLog(@"**************%ld***************",(long)count);
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView == _scrollView) { // 如果此时滑动的是_scrollView,避免影响tableView的滑动
if (scrollView.contentOffset.y < 0) {
scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
}
if (scrollView.contentOffset.y > 0) {
scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
}
}
这样写是可以的啊,你坑定是别的地方埋了坑
{
{