我遇到了UICollectionView的滚动问题。我的手机包含图片和一些文字标签。
我试图检查导致这种情况的原因,当我禁用标签的设置时,一切都很顺利,当我为两个以上的标签设置文字时,滚动又是生涩的......
有谁知道如何解决它?
这是我的代码:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ResultCell";
ResultCellView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
if ([self.artworksSavedForLater containsObject:indexPath]) {
cell.saveForLaterButton.selected = YES;
} else cell.saveForLaterButton.selected = NO;
Artwork *artwork = [self.dataHelper.fetchedResultsController objectAtIndexPath:indexPath];
cell.title.text = artwork.title;
cell.owner.text = artwork.owner;
cell.fields.text = artwork.fields;
cell.numberOfViews.text = [NSString stringWithFormat:@"%@",artwork.views];
cell.numberOfLikes.text = [NSString stringWithFormat:@"%@",artwork.likes];
cell.numberOfComments.text = [NSString stringWithFormat:@"%@",artwork.comments];
cell.publishedDate.text = artwork.publishedDate;
if ([artwork.hasThumbnail boolValue]) {
dispatch_queue_t downloadQueue = dispatch_queue_create("imagecache", NULL);
dispatch_async(downloadQueue, ^{
UIImage *productImage = [UIImage imageWithData:artwork.thumbnail];
CGSize imageSize = productImage.size;
UIGraphicsBeginImageContext(imageSize);
[productImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
productImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_async(dispatch_get_main_queue(), ^ {
cell.thumbnailImage.image = productImage;
cell.thumbnailImage.hidden = NO;
});
});
}
else {
cell.thumbnailImage.hidden = YES;
[self startOperationsForPhotoRecord:artwork atIndexPath:indexPath];
}
return cell;
我的手机代码:
- (void)didMoveToSuperview {
[super didMoveToSuperview];
self.title.font = [UIFont fontWithName:@"VerbRegular" size:14.0];
self.layer.borderColor = [UIColor colorWithWhite:0.19f alpha:1.0f].CGColor;
self.layer.borderWidth = 1.0f;
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
self.layer.shouldRasterize = YES;
}
- (void)prepareForReuse
{
[super prepareForReuse];
self.thumbnailImage.image = nil;
}
答案 0 :(得分:2)
我找到了UICollectionView的动态滚动解决方案,动态设置了许多标签。
我没有使用标签,而是使用Miroslav Hudak在这篇文章中描述的drawLabel方法绘制所有NSStrings:
How to change color of NSString in drawAtPoint
现在我的UICollectionView滚动顺畅:)