UITableView上的sendSubviewToBack在iOS 11中无法正常工作(sendSubviewToBack on UITableView not working properly in iOS 11)
我有一个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;但是,这不再适用于iOS 11,并且bgView实际上被放置在所有单元格之上。
任何人都知道如何解决这个问题? 或者也许我一直在做错事情?
I have an UITableViewController to which I successfully applied in the past a gradient background, by sending the newly added subview to back:
//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;However, this no longer works in iOS 11 and the bgView is actually placed on top of all the cells.
Anyone knows how I can fix this? Or maybe I was doing it wrong all the time?
最满意答案
如果你的单元格是透明的,那么你可以尝试self.tableView.backgroundView = bgView;
If your cells are transparent then you can try self.tableView.backgroundView = bgView;
更多推荐
发布评论