IT/유용한 사이트

[Swift] AutoLayout 어디가 문제인지 확인해보자!

언클린 2022. 1. 1. 10:21
728x90

Storyboard 나 xib 파일에서 레이아웃을 설정하지 않고 코드에서 레이아웃을 설정할 경우

간혹 오류가 발생하거나 적용이 되지 않는 모습을 보실 수 있습니다.

또 로그 창에서 Unable to simultaneously satisfy constraints. 라고 하면서

뭔가 문제가 있다고 알려줍니다.

이번 글에서는 해당 안내를 쉽게 알아볼 수 있는 사이트에 대해 공유드리겠습니다.


1. URL

https://www.wtfautolayout.com/

 

WTF Auto Layout?

Make sense of cryptic Auto Layout error logs.

www.wtfautolayout.com

네... 좀 사이트 이름이 그렇긴 한데 도움이 되는 사이트입니다 (0_0)

2. 사용법

우선은 레이아웃에 문제를 발생시켜봅니다. (정말 간단하게 것들만 해보았습니다.)

그러면 아래와 같은 문구가 발생합니다.

                                Demo[14848:75767] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600001969b80 Demo.DemoView:0x7f9fa7f11fc0.height == 52   (active)>",
    "<NSLayoutConstraint:0x60000196a3f0 Demo.DemoView:0x7f9fa7f11fc0.top == UILayoutGuide:0x60000039a140'UIViewSafeAreaLayoutGuide'.top   (active)>",
    "<NSLayoutConstraint:0x600001930820 'UIView-Encapsulated-Layout-Height' UIView:0x7f9fd0a86820.height == 667   (active)>",
    "<NSLayoutConstraint:0x60000196a210 'UIViewSafeAreaLayoutGuide-top' V:|-(20)-[UILayoutGuide:0x60000039a140'UIViewSafeAreaLayoutGuide']   (active, names: '|':UIView:0x7f9fd0a86820 )>"
)

자 여기서 괄호 안에 있는 문구들을 복사한 뒤, 해당 URL에 입력 후 Go! 버튼을 클릭하면??

아래와 같이 간단하게 해석해서 보여줍니다.

그리고 나서 하나씩 수정해 나아가면 완료!

 

마무리

개발을 진행하다 보면 가끔씩 맞닥뜨리는 문제인데 해당 사이트로 많은 도움을 받고 있습니다.

감당이 안될 정도로 많은 오류가 발생한다면 한 번 사용해 보는 것도 좋을 것 같습니다.

감사합니다!(_ _)


환경 

Xcode 13.2.1

Swift 5

 

 

 

 

728x90