본문 바로가기

iOS/STUDY

[iOS] UIToolbar 이슈 (UIToolbarContentView, UIButtonBarStackView)

    "<NSAutoresizingMaskLayoutConstraint:0x600000b5d3b0 h=--& v=--& _UIToolbarContentView:0x13b13c270.width == 0   (active)>",
    "<NSLayoutConstraint:0x600000b506e0 H:|-(16)-[_UIButtonBarStackView:0x13b13c590]   (active, names: '|':_UIToolbarContentView:0x13b13c270 )>",
    "<NSLayoutConstraint:0x600000b50730 H:[_UIButtonBarStackView:0x13b13c590]-(16)-|   (active, names: '|':_UIToolbarContentView:0x13b13c270 )>"

 

 

키보드 위에 버튼을 나타내기 위해 툴바를 사용했는데 

이 오류가 처음 화면에는 안나타나고.. 다시 화면에 재진입할때 발생한다.

 

WTF 홈페이지랑 콘솔창에서 translatesAutoresizingMaskIntoConstraints

를 확인해보라고 해서 버튼 false 툴바 false 지우고 지우고 sizeToFit도 건드려보고 별짓 다해봤는데 안되길래 구글 검색

 

가장 첫 글에 발견

https://developer.apple.com/forums/thread/121474

 

UIToolbar issue in iOS 13 | Apple Developer Forums

I'm adding one UIBarButtonItem with a custom view. The custom view uses autolayout to layout its inner components. Is this supported in iOS 13? This issue does not happen when the same code is run against an iOS 12 device. Adding just one UIBarButtonItem w

developer.apple.com

 

읽고 읽다가 자신도 왜이렇게 되는지 모르겠는데 선언 시 frame 걸어주면 해결된다고 한다.. 진짜..?

 

let doneToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

 

아무 값이나 걸어주었는데 진짜 오류가 안뜬다.

..!

 

스택오버플로우에서도 같은 답변

https://stackoverflow.com/questions/54284029/uitoolbar-with-uibarbuttonitem-layoutconstraint-issue

 

UIToolbar with UIBarButtonItem LayoutConstraint issue

I'm creating a UIToolbar with UIBarButtonItem in it programatically. I'm not using .xib or storyboard for this ViewController. Here's the code of how I created it. NSMutableArray *items = [[

stackoverflow.com

 

 

또다른 해결방법

updateConstraintsIfNeeded() 을 걸어주면 된다.

doneToolbar.updateConstraintsIfNeeded()

 

Constraints 오류인가..