ios – UIScrollView内容不允许用户交互

我有一个启用了分页的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];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...