我有一个启用了分页的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];
}
答案 0 :(得分:11)
在容器上禁用用户交互也会在子视图上有效地禁用它。您应该启用它,使触摸事件沿视图层次结构向下传播;
[container setUserInteractionEnabled:YES];
如果要在UIWebView上禁用滚动,只需进入其UIScrollView
yourWebView.scrollView.scrollEnabled = NO;
我已经在我的设备上对此进行了测试,我可以通过"翻页和#34; UIScrollView并在UIWebView上选择文本。
编辑:
我得到了这个工作!您还必须允许触摸取消:
[container setCanCancelContentTouches:YES];