带有2个子视图的iOS UITableView setBackgroundView

时间:2014-09-17 20:01:51

标签: ios uitableview uiimageview

我尝试使用tableviews在iOS上执行特定效果时遇到问题...我知道这可以通过普通的UIViewControllers完成,但似乎无法用UITableViewControllers将其拉出来。 / p>

效果在桌面视图后面显示清晰的背景图像,并且当用户向下滚动桌面视图时,背景模糊。没问题可以实现。

我遇到的问题是使用UITableViewController,我似乎只能在TableView后面有1个ImageView并创建模糊效果,我使用的扩展需要2个图像视图,其中一个是模糊的图像,并在启动时将其不透明度设置为0。

这是我知道使用UIViewController工作的代码:

UIImage *background = [UIImage imageNamed:@"bg_004.png"];

self.backgroundImageView = [[UIImageView alloc] initWithImage:background];
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:self.backgroundImageView];

self.blurredImageView = [[UIImageView alloc] init];
self.blurredImageView.contentMode = UIViewContentModeScaleAspectFill;
self.blurredImageView.alpha = 0;
[self.blurredImageView setImageToBlur:background blurRadius:10 completionBlock:nil];
[self.view addSubview:self.blurredImageView];

这是我在UITableViewController上尝试的代码不起作用:

UIImage *background = [UIImage imageNamed:@"bg_004.png"];
self.backgroundImageView = [[UIImageView alloc] initWithImage:background];
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;

[self.tableView setBackgroundView:self.backgroundImageView];

// Also tried this, to no success
[self.tableView.backgroundView addSubview:self.blurredBackgroundView];

self.blurredBackgroundView = [[UIImageView alloc] init];
self.blurredBackgroundView.contentMode = UIViewContentModeScaleAspectFill;
self.blurredBackgroundView.alpha = 0;

[self.blurredBackgroundView setImageToBlur:background blurRadius:10 completionBlock:nil];
[self.tableView setBackgroundView:self.blurredBackgroundView];

// Also tried this, to no success
[self.tableView.backgroundView addSubview:self.blurredBackgroundView];

如果有人对如何使这项工作有一些建议,我会喜欢一些建议。我真的不想将我的代码从TableViewController更改为UIViewController

1 个答案:

答案 0 :(得分:0)

将表格视图的backgroundView属性设置为指向UIView的实例,然后将您的图片视图添加为新视图的子视图。您无法直接将子视图添加到UIImageView

的实例中