UITableView上的sendSubviewToBack在iOS 11中无法正常工作(sendSubviewToBack on UITableView not working properly i

编程入门 行业动态 更新时间:2024-10-27 20:25:34
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;

更多推荐

本文发布于:2023-07-26 00:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   工作   iOS   sendSubviewToBack   UITableView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!