UITableViewWrapperView
。
我正在使用UITableView
的{{1}}方法设置我的insertSubview
的背景视图,当我使用Xcode8编译代码时,该代码适用于所有iOS版本,但是当我构建时使用Xcode9的相同代码然后内容是不可见的(在iOS 11上),因为背景层来自单元格。
以下是调试结果 -
Xcode9和iOS 11 -
一个。在添加背景之前
UIView
B中。添加背景后
▿ 2 elements - 1 : <UIImageView: 0x7fe7f5f045c0; frame = (3 710.667; 408 2.33333); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x604000223f80>> - 2 : <UIImageView: 0x7fe7f5f01e30; frame = (408.667 3; 2.33333 385); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled> = NO; layer = <CALayer: 0x604000226720>>
Xcode8和iOS 11 - 存在UITableViewWrapperView -
一个。在添加背景之前
▿ 3 elements - 0 : <UIView: 0x7fe7f5e09840; frame = (0 0; 414 736); layer = <CALayer: 0x60400003d780>> - 1 : <UIImageView: 0x7fe7f5f045c0; frame = (3 710.667; 408 2.33333); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x604000223f80>> - 2 : <UIImageView: 0x7fe7f5f01e30; frame = (408.667 3; 2.33333 385); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled> = NO; layer = <CALayer: 0x604000226720>>
B中。添加背景后
3 elements - 0 : <UITableViewWrapperView: 0x7ffdbe81cc00; frame = (0 0; 375 647); gestureRecognizers = <NSArray: 0x608000244a10>; layer => <CALayer: 0x608000028cc0>;contentOffset: {0, 0}; contentSize: {375,> 647}> - 1 : <UIImageView: 0x7ffdbe406af0; frame = (3 641.5; 369 2.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO;layer = <CALayer: 0x608000028fe0>> - 2 : <UIImageView: 0x7ffdbe407320; frame = (369.5 637; 2.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO;> layer = <CALayer: 0x608000029140>>
设置背景的方法 -
4 elements
- 0 : <UIView: 0x7ffdbe505cc0; frame = (0 0; 375 667); layer = <CALayer: 0x60000002a460>>
- 1 : <UITableViewWrapperView: 0x7ffdbe81cc00; frame = (0 0; 375 647); gestureRecognizers = <NSArray: 0x608000244a10>; layer =<CALayer: 0x608000028cc0>; contentOffset: {0, 0};contentSize: {375,647}>
- 2 : <UIImageView: 0x7ffdbe40b0f0; frame = (3 641.5; 369 2.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO;layer = <CALayer: 0x608000029e00>>
- 3 : <UIImageView: 0x7ffdbe40b550; frame = (369.5 637; 2.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO;layer = <CALayer: 0x608000029f00>>
在iOS11上使用Xcode8构建
在iOS11上使用Xcode9构建
我找到this链接,确认从iOS11中删除 private func setTableViewBackground() {
let backgroundView = UIView()
backgroundView.frame = view.frame
let maskPath: UIBezierPath = UIBezierPath(roundedRect: backgroundView.bounds, byRoundingCorners: ([.topLeft, .topRight]), cornerRadii: CGSize(width:20, height:20))
let maskLayer: CAShapeLayer = CAShapeLayer()
maskLayer.frame = backgroundView.bounds
maskLayer.path = maskPath.cgPath
backgroundView.layer.mask = maskLayer
backgroundView.backgroundColor = UIColor.red
myCustomTableView.insertSubview(backgroundView, at: 0)
}
,但是当我们使用Xcode9编译代码时?
答案 0 :(得分:1)
这就是为什么我不喜欢使用未记录的功能。苹果公司根据需要改变它们而不通知。 我对你的案例的建议是将表格视图放在IB中的红色基板上并应用你的代码。
NB。不要忘记将clipsToBounds
属性设置为true
。
该功能将更短:
private func setTableViewBackground() {
let backgroundView = self.tableViewSubstrate!
let maskPath: UIBezierPath = UIBezierPath(roundedRect: backgroundView.bounds, byRoundingCorners: ([.topLeft, .topRight]), cornerRadii: CGSize(width:20, height:20))
let maskLayer: CAShapeLayer = CAShapeLayer()
maskLayer.path = maskPath.cgPath
backgroundView.layer.mask = maskLayer
}
您可以在此处找到示例项目:https://github.com/AlexeyGolovenkov/TableWithRoundCorners
答案 1 :(得分:0)
检查目标构建设置。您可能正在构建最新的操作系统并从XCode 8切换到9将编译目标操作系统从10移动到11.这也可能是任何调试版本与发布版本之间的区别。您可以将XCode 9中的目标更改为iOS 10,并且会在修复问题的情况下重新编译,但您将来可能存在弃用问题。
答案 2 :(得分:0)
尝试将myCustomTableView.insertSubview(backgroundView, at: 0)
替换为
myCustomTableView.backgroundView = backgroundView
它对我来说很好。
答案 3 :(得分:-1)
兄弟我认为以下代码行可能对您有用。
旧代码:
private func setTableViewBackground() {
let backgroundView = UIView()
backgroundView.frame = view.frame
let maskPath: UIBezierPath = UIBezierPath(roundedRect: backgroundView.bounds, byRoundingCorners: ([.topLeft, .topRight]), cornerRadii: CGSize(width:20, height:20))
let maskLayer: CAShapeLayer = CAShapeLayer()
maskLayer.frame = backgroundView.bounds
maskLayer.path = maskPath.cgPath
backgroundView.layer.mask = maskLayer
backgroundView.backgroundColor = UIColor.red
myCustomTableView.insertSubview(backgroundView, at: 0)
}
替换为以下代码:
private func setTableViewBackground() {
let backgroundView = UIView()
backgroundView.frame = view.frame
let maskPath: UIBezierPath = UIBezierPath(roundedRect: backgroundView.bounds, byRoundingCorners: ([.topLeft, .topRight]), cornerRadii: CGSize(width:20, height:20))
let maskLayer: CAShapeLayer = CAShapeLayer()
maskLayer.frame = backgroundView.bounds
maskLayer.path = maskPath.cgPath
backgroundView.layer.mask = maskLayer
backgroundView.backgroundColor = UIColor.red
// myCustomTableView.insertSubview(backgroundView, at: 0)
myCustomTableView.backgroundView = backgroundView
}