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];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...