UIScrollView与UIButtons'跳过'当手指拖动到其超视图边界之外

时间:2011-09-15 05:00:27

标签: objective-c uiscrollview uibutton

我将scrollView设置为titleView的{​​{1}}。 navigationBar的{​​{1}}中有4个按钮,所有按钮都是动态布局的。这些按钮需要通过拖动和滚动来取消,因此我在contentView时将它们分类到scrollView

当我尝试滚动scrollView时,只要我越过superview的边界(即传递bottom或top bounds navigationBar),scrollview'跳过'8或11像素,这取决于它是否是顶部或按钮。它与setEnabled:NO有关,因为当我使用touchesMoved时问题不会持续存在。

相关代码:

Scrollview初始化:

UIButtons

按钮初始化(-layoutMenu):

UILabels

跳过时,按钮上没有调用任何事件, menuWidth = 196; rowHeight = 40; rowMargin = self.frame.size.height - rowHeight; //drop down menu stuff self.scrollView = [[UIScrollView alloc] initWithFrame:self.frame]; scrollView.backgroundColor = [UIColor clearColor]; scrollView.contentSize = CGSizeMake(self.frame.size.width, (self.frame.size.height)*choices.count); scrollView.pagingEnabled = YES; scrollView.showsVerticalScrollIndicator = NO; scrollView.showsHorizontalScrollIndicator = NO; scrollView.clipsToBounds = YES; scrollView.canCancelContentTouches = YES; scrollView.delaysContentTouches = YES; scrollView.delegate = self; [self layoutMenu]; [self addSubview:scrollView]; [scrollView release]; 只发生正常看似SKScrollableButton *tempButton; NSString *text; for (int i = 0; i < choices.count; i++) { text = (NSString*)[choices objectAtIndex:i]; if (i == 0) { text = [text stringByAppendingString:downArrow]; } CGRect labelRect = CGRectMake(0, i*(rowHeight + rowMargin), menuWidth, rowHeight - 7); tempButton = [[SKScrollableButton alloc] initWithFrame:labelRect]; [tempButton setTitle:text forState:UIControlStateNormal]; [tempButton addTarget:self action:@selector(buttonDown:) forControlEvents:UIControlEventTouchDown]; [tempButton addTarget:self action:@selector(buttonUpInside:) forControlEvents:UIControlEventTouchUpInside]; [self.scrollView addSubview:tempButton]; [tempButton release]; } 委托调用。

我已经测试过了,并且在传递superview的边界时肯定会跳过,而不是scrollViewDidScroll本身的边界。

0 个答案:

没有答案