可滚动且与UITable滚动同步的背景图像 [英] Background image that's scrollable and in synch with the UITable scrolling

查看:62
本文介绍了可滚动且与UITable滚动同步的背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用以下代码将图像添加到UITableview中.我不知道如何使背景图像随表格滚动(不是每个单元格中的图像,而是UITable后面的大图像).我需要背景图片可滚动并与UITable滚动同步.

I've added an image to a UITableview using the following code. What I can't figure out is how to have that background image scroll with the table (not an image in each cell, but a large image behind the UITable). I need the background image to be scrollable and in synch with the UITable scrolling.

我已经搜索过,并且我看到的所有示例都只是添加了静态图像.

I've searched and all the examples I've seen simply add a static image.

这是代码:

[self.view setBackgroundColor:
 [UIColor colorWithPatternImage:
  [UIImage imageWithContentsOfFile:
   [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
    @"background.png"]]]];

感谢您的帮助.

推荐答案

我遇到了同样的问题,没有找到任何解决方案.我翻了自己的书,比这里容易讲解的要详细解释.在 UITableView中进行了解释使用动态内容滚动背景

I had this same problem and didn't find any solutions. I rolled my own which I explain in more detail than can be easily given here. It's explained at UITableView that scrolls the background with dynamic content

基本思想如下:

  • 在表格视图后创建第二个表格视图,该表格视图具有动态单元格高度(或不是背景图案图像高度的倍数的高度)
  • 将其.userInteractionEnabled属性设置为NO(这样它就不会收到触摸事件)
  • 让它通过KVO监听前"表视图的contentOffset属性,以便后台表视图将其contentOffset设置为相同的值.
  • 让此背景表视图为其自己的委托(您必须创建一个子类,以便无论如何实现KVO侦听处理程序),并填充空单元格的contentView.backgroundColor = [UIColor colorWithPatternImage:...]
  • 确保前"表视图单元格具有透明背景.即backgroundView设置为imageView,而没有图像和不透明性设置为NO,backgroundColor设置为clearColor.

为我工作得很好,而且似乎丝毫没有变慢.在iPod 4G上,桌子仍然很活泼

worked for me quite fine, and didn't seem in any way slower. The tables were still quite snappy on an iPod 4G

这篇关于可滚动且与UITable滚动同步的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆