【问题标题】:Scroll jumping with nib custom cell and autolayout (ios 8 swift - UITableview)使用 nib 自定义单元格和自动布局滚动跳转(ios 8 swift - UITableview)
【发布时间】:2015-08-06 06:22:39
【问题描述】:

我已经从这个参考中实现了带有自动布局的自定义单元格:https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8

在我的单元格中,我有一个 imageView 和 5 个带有动态内容的标签。

我想要实现的是类似于 Facebook 的提要,其中每个单元格的图像大小都不同。我有图像大小的元数据。

我尝试使用estimatedHeightForRow 并给出了一些平均高度。

布局中一切正常,但滚动时会跳动。

如何提高我的 tableview 滚动性能?

【问题讨论】:

  • 您在滚动期间是否在执行任何后台任务?例如网络请求或其他内容?
  • 我正在异步下载图像让块:SDWebImageCompletionBlock! = {(image: UIImage!, error: NSError!, cacheType: SDImageCacheType, imageURL: NSURL!) -> self.ImageFeedView.sd_setImageWithURL(self.cueData.attachments[0].URL);} self.ImageFeedView.sd_setImageWithURL (self.cueData.attachments[0].URL, completed:block)
  • iOS8 自动尺寸有问题,请使用 iOS7 变体 - github.com/smileyborg/TableViewCellWithAutoLayout
  • 你在后台做异步操作吗?你从哪里得到每个单元格的文本?这不也是网络调用吗? (也许是一些 JSON WepApi?)
  • @Darko 我的集合对象中有数据(NSMutableArray)

标签: iphone swift uitableview ios8 autolayout


【解决方案1】:

您已在某些 cmets 中发布了此代码:

    let block: SDWebImageCompletionBlock! = {
        (image: UIImage!, error: NSError!, cacheType: SDImageCacheType, imageURL: NSURL!) -> Void in
        self.ImageFeedView.sd_setImageWithURL(self.cueData.attachments[0].URL);
    }

    self.ImageFeedView.sd_setImageWithURL(self.cueData.attachments[0].URL, completed:block)

您正在设置图像两次。首先是:

self.ImageFeedView.sd_setImageWithURL(self.cueData.attachments[0].URL, completed: block)

然后,完成块中的相同图像。这是不必要的,可能导致口吃。只需删除块并执行以下操作:

self.ImageFeedView.sd_setImageWithURL(self.cueData.attachments[0].URL)

现在口吃应该好多了。 (甚至解决,请尝试)

【讨论】:

  • 我已经评论了设置图像并从本地提供图像但滚动仍然很跳跃
  • @Kirankoneti 我遇到了同样的问题。你得到这个解决方案了吗
【解决方案2】:

上传大图时,表格有时会抖动。也许尝试解码收到的照片:

UIImage *anImage = ...  // Assume this exists.
CGImageRef originalImage = (CGImageRef)anImage;
assert(originalImage != NULL);

CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider(originalImage));
CGDataProviderRef imageDataProvider = CGDataProviderCreateWithCFData(imageData);
if (imageData != NULL) {
  CFRelease(imageData);
}
CGImageRef image = CGImageCreate(CGImageGetWidth(originalImage),
                                 CGImageGetHeight(originalImage),
                                 CGImageGetBitsPerComponent(originalImage),
                                 CGImageGetBitsPerPixel(originalImage),
                                 CGImageGetBytesPerRow(originalImage),
                                 CGImageGetColorSpace(originalImage),
                                 CGImageGetBitmapInfo(originalImage),
                                 imageDataProvider,
                                 CGImageGetDecode(originalImage),
                                 CGImageGetShouldInterpolate(originalImage),
                                 CGImageGetRenderingIntent(originalImage));
if (imageDataProvider != NULL) {
  CGDataProviderRelease(imageDataProvider);
}

// Do something with the image.

CGImageRelease(image);

从 CGImageCreate() 接收到的图像已经解码,这正是我们需要的。剩下的就是将此代码包装在 NSOperation 中以在后台执行它,最后将结果发送到主线程。使用 +[UIImage imageWithCGImage:] 我们从生成的 CGImage 中获取 UIImage,并在滚动期间将其分配给所需的 UIImageView。动画完美无瑕。

【讨论】:

  • swift中有这个功能吗?
猜你喜欢
  • 1970-01-01
  • 2019-07-22
  • 1970-01-01
  • 2018-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多