[英]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
。 我不明白出了什么问题,所以如果有人可以在这里帮助我,那真是太好了。 我究竟做错了什么?
原来的问题是我正在将UIScrollView
发送到UICollectionViewCell
的背面。 删除[self sendSubviewToBack:self.background];
解决了问题。
UIWebView子视图正在处理平移手势。 尝试在Web视图上禁用触摸互动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.