我有一个启用了分页的UIScrollView,如下所示:
container = [[UIScrollView alloc] initWithFrame:kScrollViewFrame]; [container setDelegate:self]; [container setShowsHorizontalScrollIndicator:YES]; [container setShowsVerticalScrollIndicator:NO]; [container setClipsToBounds:YES]; [container setPagingEnabled:YES]; [container setDecelerationRate:UIScrollViewDecelerationRateFast]; [container setBounces:NO]; [container setUserInteractionEnabled:NO]; [container setCanCancelContentTouches:NO]; [container setDelaysContentTouches:NO];
在UIScrollView中,我添加了几个UIWebViews,并将其启用的交互设置为是这样的.
- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code self.frame = frame; self.userInteractionEnabled = YES; } return self; }
它打破了UIScrollView上的分页和所有触摸.如果我将用户交互设置为NO,则页面有效,但我无法在UIWebView中突出显示文本.我试着像下面那样对UIScrollView进行子类化,但是会出现同样的情况.任何的想法?
- (id)initWithFrame:(CGRect)frame { NSLog(@"init"); return [super initWithFrame:frame]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesBegan"); [[self nextResponder] touchesBegan:touches withEvent:event]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesMoved"); [[self nextResponder] touchesMoved:touches withEvent:event]; } - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesEnded"); [[self nextResponder] touchesEnded:touches withEvent:event]; }
解决方法
禁用容器上的用户交互也会在子视图上有效地禁用它.您应该启用它,使触摸事件沿视图层次结构向下传播;
[container setUserInteractionEnabled:YES];
如果要在UIWebView上禁用滚动,只需进入其UIScrollView
yourWebView.scrollView.scrollEnabled = NO;
我在我的设备上测试了这个,我可以“浏览”UIScrollView并在UIWebView上选择文本.
编辑:
我有这个工作!您还必须允许触摸取消:
[container setCanCancelContentTouches:YES];