UITableView上的sendSubviewToBack在iOS 11中无法正常工作

Cri*_*tiC 8 objective-c ios11

我有一个UITableViewController我通过将新添加的子视图发送回来成功应用于过去的渐变背景:

//performed on viewDidLoad
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1.5*280, 1.5*SCREEN_HEIGHT)];
bgView.backgroundColor = [UIColor yellowColor];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = bgView.bounds;
gradient.startPoint = CGPointMake(0, 0);
gradient.endPoint = CGPointMake(1, 1);
UIColor *topColor = UIColorFromRGB(0x229f80);
UIColor *bottomColor = UIColorFromRGB(0x621ad9);
gradient.colors = [NSArray arrayWithObjects:(id)[topColor CGColor], (id)[bottomColor CGColor], nil];
[bgView.layer insertSublayer:gradient atIndex:0];
[self.view addSubview:bgView];
[self.view sendSubviewToBack:bgView];
bgView = nil;
Run Code Online (Sandbox Code Playgroud)

但是,这在iOS 11中不再有效,而bgView实际上放在所有单元格的顶部.

在此输入图像描述

谁知道我怎么解决这个问题?或者也许我一直都在做错?

Jos*_*had 3

如果你的细胞是透明的那么你可以尝试self.tableView.backgroundView = bgView;