我需要有一个iphone X的表格视图,其边距相对于安全区布局指南:
这是我得到的结果: 差距下注太多。我的资料检视的左边缘和边缘
我试图像这样设置原点(x):
view.frame.width - view.safeAreaLayoutGuide.width
let x = view.safeAreaLayoutGuide.origin.x
这是我的下面的代码:
var safeAreainsets: UIEdgeInsets {
if #available(iOS 11.0, *) {
guard let window = UIApplication.shared.keyWindow else { return UIEdgeInsets.zero }
return window.safeAreaInsets
}
return UIEdgeInsets.zero
}
var layoutFrame: CGRect {
let guide = view.safeAreaLayoutGuide
return guide.layoutFrame
}
var hasSafeArea: Bool {
return safeAreainsets.top > 0 || safeAreainsets.right > 0 || safeAreainsets.bottom > 0 || safeAreainsets.left > 0
}
//property to check if device is iPhoneX - not completely future proof though
fileprivate var isIphoneX: Bool {
if layoutFrame.width - view.frame.width != 0 { return true }
return false
}
fileprivate var tableViewFrame: CGRect {
//calculating margins value if applicable
let margins = shouldShowFlexibleHeader && isRegular && isLandscape ? (view.frame.width * 10) / 100 : 0
//setting tableView frame with following conditions
let x = view.frame.width - layoutFrame.width
if isIphoneX {
return CGRect(x: isLandscapeLeft ? x : 0, y: 0, width: view.frame.width, height: view.frame.height)
} else {
return CGRect(x: margins / 2, y: 0, width: view.frame.width - margins, height: view.frame.height)
}
}