UICollectionViewCell 内的 UIScrollView 不滚动

UIScrollView inside UICollectionViewCell not scrolling

我正在设置 UICollectionViewCell这样的:

    self.background = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height)];
    self.background.userInteractionEnabled = YES;
    self.background.scrollEnabled = YES;
    self.background.showsVerticalScrollIndicator = YES;

    // configure image
    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.background.frame.size.height)];

    [self.background addSubview:self.image];

    // configure title
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(5, 10, self.contentView.frame.size.width-10, 70)];
    [self.background addSubview:self.title];

    // configure description
    self.description = [[UILabel alloc] initWithFrame:CGRectMake(5, 80, self.contentView.frame.size.width-10, 20)];
    [self.background addSubview:self.description];

    self.textView = [[UIWebView alloc] initWithFrame:CGRectMake(0, self.image.frame.size.height+10, self.contentView.frame.size.width, 40)];
    self.textView.delegate = self;
    NSString *content = [NSString stringWithFormat:@"<html><head></head><body id='foo'>%@</body></html>", @"<p>kbafdj akdjfnadf jhadkfb ij daofhu adofh oj afoduuh oiad fohfd ouhadf dj aodfhj ah adlfk ohad ofladjhfl aojadf oadfh oadhf adfladf adfoadf oadfh aodfh a oadf aodf  afdjladf oad jladfl aodf alf d  adjfladf   adfj aldfkajdfljad aodfj adlfj ad aldjf adlfj al adfjadlfa d adf adf ad pajdf aldjf adkh pfbd fpqehf qehf qepd af pqif phhf q piiqihpsdhvpvqohro pdh wpvhqf lorem ipsum dfkbshbs k bfjsv ohfakdjb </p>"];
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    [_textView loadHTMLString:content baseURL:baseURL];
    [self.background addSubview:_textView];

    [self addSubview:self.background];
    [self sendSubviewToBack:self.background];
    [self.background setContentSize:CGSizeMake(self.contentView.frame.size.width, 2*self.contentView.frame.size.height)];

UICollectionView 具有水平滚动的全屏 UICollectionViewCell 功能。 UICollectionView 上还有一个 UIGestureRecognizer:

self.pinchRecognizer =
[[UIPinchGestureRecognizer alloc] initWithTarget:self                                    action:@selector(closeCell:)];
self.pinchRecognizer.delegate = self;
[_collectionView addGestureRecognizer:self.pinchRecognizer];

现在,UIScrollView 不起作用。我不明白出了什么问题,所以如果有人能在这里帮助我,那就太好了。我做错了什么?

可能是 UIWebView 子视图正在处理平移手势。尝试在 webview 上禁用触摸交互。

原来问题是我将 UIScrollView 发送到 UICollectionViewCell 的后面。删除 [self sendSubviewToBack:self.background]; 解决了问题。