programing

UIScrollView는 자동 레이아웃 제약 조건을 사용하지 않습니다.

nasanasas 2020. 10. 15. 07:54
반응형

UIScrollView는 자동 레이아웃 제약 조건을 사용하지 않습니다.


스크롤 뷰와 그 뒤에 이미지 뷰가 있고 펜촉으로 채 웁니다. 자동 레이아웃을 사용하고 있습니다. 나는 두 뷰 모두에서 슈퍼 뷰를위한 하단 공간과 슈퍼 뷰를위한 상단 공간이 있습니다. 이미지보기는 내가 원하는 작업을 정확히 수행합니다. 아이폰 5의 경우 내가 원하는 곳입니다. 그리고 다른 아이폰의 경우 화면 하단에 유지되므로 크기가 올바르게 조정됩니다. 스크롤보기는 아이폰 5에서 오른쪽으로 보이지만 다른 휴대폰에서는 크기가 조정되지 않으므로 앱보기 아래로 스크롤됩니다. 로그에 다음 메시지가 표시됩니다.

 2012-11-21 10:42:38.576 LCHApp[12604:907] 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.
 (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer
  to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 

"<NSLayoutConstraint:0x1d8ea080 UIScrollView:0x1d8413b0.bottom == UIImageView:0x1d892110.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0x1d8cca10 h=-&- v=-&- ScheduleViewNib:0x1d853630.height == UIScrollView:0x1d8413b0.height - 386>",
"<NSLayoutConstraint:0x1d8e5340 V:[UIImageView:0x1d892110]-(64)-|   (Names: '|':ScheduleView:0x1d8efc30 )>",
"<NSAutoresizingMaskLayoutConstraint:0x1d8cf520 h=--& v=--& V:[ScheduleView:0x1d8efc30(480)]>",
"<NSLayoutConstraint:0x1d8eaed0 V:|-(45)-[UIScrollView:0x1d8413b0]   (Names: '|':ScheduleView:0x1d8efc30 )>"


 Will attempt to recover by breaking constraint 
 <NSLayoutConstraint:0x1d8ea080 UIScrollView:0x1d8413b0.bottom ==      UIImageView:0x1d892110.bottom>

나는 이미 시도했다

[self setTranslatesAutoresizingMaskIntoConstraints:YES];

[self.myScrollView setTranslatesAutoresizingMaskIntoConstraints:YES];

내가 볼 수 있듯이 이것은 뷰에서 모든 제약을 제거합니다. 그리고 내가 원하는 것이 아닙니다.


UIScrollView와 자동 레이아웃의 관계는 자동 레이아웃의 다른 측면과 다릅니다. 기본적으로 간단한 자동 레이아웃이 작동하도록 허용되면 아무것도 스크롤되지 않습니다. 예를 들어, 스크롤 뷰의 하위 뷰가 스크롤 뷰의 상단에서 10 개 지점에 대한 제약 조건에 의해 일반적인 방식으로 고정 된 경우 해당 위치에 절대적으로 고정됩니다. 스크롤 뷰가 어떻게 스크롤 되더라도 절대 움직이지 않습니다.

이 문제를 해결하기 위해 자동 레이아웃을 사용하는 UIScrollView는 완전히 새로운 방식으로 작동합니다. 따라서 "자동 레이아웃을 사용하고 있습니다"라고 말할 때 이전과 매우 다르게 작동 할 수 있도록 준비해야합니다. 와 함께 단일 스크롤보기 하위보기 translatesAutoresizingMaskIntoConstraints = YES및 명시 적 콘텐츠 크기를 사용해야합니다. 그렇지 않으면 모든 항목이 있어야 translatesAutoresizingMaskIntoConstraints = NO하며 콘텐츠 크기는 하위보기의 제약 조건에 따라 암시 적으로 추론됩니다.

이것은 https://developer.apple.com/library/content/releasenotes/General/RN-iOSSDK-6_0/index.html에 매우 잘 설명되어 있습니다.


자동 레이아웃을 사용할 때 매우 중요합니다. 마지막 하위보기의 오른쪽 및 / 또는 아래쪽을 스크롤보기의 오른쪽 및 / 또는 아래쪽에 고정해야합니다. 이것이 스크롤 뷰가 콘텐츠 크기를 아는 방법입니다. 예를 들면 :

[scrollView addConstraint:[NSLayoutConstraint constraintWithItem:lastSubView
                                                 attribute:NSLayoutAttributeRight
                                                 relatedBy:NSLayoutRelationEqual
                                                    toItem:scrollView
                                                 attribute:NSLayoutAttributeRight
                                                multiplier:1.0
                                                  constant:0]];

완벽한 예를 제공 한이 사이트감사드립니다 .

이 때문에 시간을 잃었고 다른 사람들에게 내 고통을 아끼고 싶습니다.


UIScrollviews가 제약 조건과 잘 작동하도록하려면 여기에 대답 한이 접근 방식을 사용합니다 . 그 대답에서 나는 장치 회전에서도 작동 하는 수직 스크롤 스크롤 뷰 를 얻는 방법을 다룹니다. 가로로 스크롤하는 스크롤 뷰로 작업하도록 접근 방식을 조정할 수도 있습니다. 양방향으로 스크롤되는 scrollview의 경우 크기 일치 너비 제약 트릭을 추가 하지 마십시오 . 그러나 다른 모든 것을 동일하게하십시오.


몇 가지.

  1. 자동 레이아웃이 켜져 있는지 확인합니다 ( "파일 검사기 탭"의 IB).
  2. Make sure you are NOT making any changes that involve bounds, frame, etc. - this is all done by Auto constraints now
  3. Make sure you stay away from AutoResizingMask. This will compete with your new settings. If these are done right, you can now layout your button and it will work great. Here's how.

This error is stating that either your nib or an a control within that nib is NOT using auto layout.

참고URL : https://stackoverflow.com/questions/13499467/uiscrollview-doesnt-use-autolayout-constraints

반응형