0
보기의 제약 조건에 대한 확장을 생성했습니다. 아래에서 코드를 찾을 수 있지만 새로운 릴리스 이후 iPhone X에서는 safeAreaInsets를 사용해야하지만이 속성을 구현하는 방법을 모르겠습니다. 네가 나를 도울 수 있다면 정말 기뻐할거야.safeAreaInsets를 현재 제약 조건 확장에 통합하는 방법
감사
extension UIView {
func anchor (top: NSLayoutYAxisAnchor?, left: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, right: NSLayoutXAxisAnchor?, paddingTop: CGFloat, paddingLeft: CGFloat, paddingBottom: CGFloat, paddingRight: CGFloat, width: CGFloat, height: CGFloat) {
translatesAutoresizingMaskIntoConstraints = false
if let top = top {
self.topAnchor.constraint(equalTo: top, constant: paddingTop).isActive = true
}
if let left = left {
self.leftAnchor.constraint(equalTo: left, constant: paddingLeft).isActive = true
}
if let right = right {
rightAnchor.constraint(equalTo: right, constant: -paddingRight).isActive = true
}
if let bottom = bottom {
bottomAnchor.constraint(equalTo: bottom, constant: -paddingBottom).isActive = true
}
if height != 0 {
heightAnchor.constraint(equalToConstant: height).isActive = true
}
if width != 0 {
widthAnchor.constraint(equalToConstant: width).isActive = true
}
}
}
나는 당신이 쓴 코드를 구현하려고하지만 당신은 아이폰 OS (11) 폐쇄에 중단 점을 설정 한이 topInset의 값은 항상 0.0 –
를 돌려 작동하지 않았다? –
그리고 vc의 루트보기에서 확장 메서드를 호출하고 있습니까? –