2012-09-20 3 views
2

안녕하세요, UIScrollViewModalViewController의 자동 레이아웃 문제가 있습니다.iOS AutoLayout ScrollView 문제

1) 나는 내가 scrollView

2 서브 뷰를 추가

2)이 작동하는 UIScrollView

UIViewController *viewController = [[UIViewController alloc] init]; 
UIScrollView *scrollView = [[UIScrollView alloc] init]; 

scrollView.translatesAutoresizingMaskIntoConstraints = NO; 
[viewController.view addSubview:scrollView]; 

UIView *superView = viewController.view; 
NSDictionary *viewsDict = NSDictionaryOfVariableBindings(superView,scrollView); 

[superView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView(==superView)]|" 
                    options:0 
                    metrics:nil 
                    views:viewsDict]]; 
[superView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView(==superView)]|" 
                    options:0 
                    metrics:nil 
                    views:viewsDict]]; 

subView로와 함께 UIViewController 있습니다 다음 샘플 코드로 내 코딩 단계는

UIView *view1 = [[UIView alloc] init]; 
view1.backgroundColor = [UIColor redColor]; 
view1.translatesAutoresizingMaskIntoConstraints = NO; 
[scrollView addSubview:view1]; 


UIView *view2 = [[UIView alloc] init]; 
view2.backgroundColor = [UIColor greenColor]; 
view2.translatesAutoresizingMaskIntoConstraints = NO; 
[scrollView addSubview:view2]; 

viewsDict = NSDictionaryOfVariableBindings(scrollView,view1,view2); 


[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view1(==scrollView)]|" 
                    options:0 
                    metrics:nil 
                    views:viewsDict]]; 
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view2(==scrollView)]|" 
                    options:0 
                    metrics:nil 
                    views:viewsDict]]; 

[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view1(180)][view2(==scrollView)]|" 
                    options:0 
                    metrics:nil 
                    views:viewsDict]]; 


UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[btn setTitle:@"open" forState:UIControlStateNormal]; 
btn.frame = CGRectMake(10, 10, 100, 100); 
[view2 addSubview:btn]; 
[btn addTarget:self action:@selector(openPopOver) forControlEvents:UIControlEventTouchUpInside]; 

잘 작동합니다.

,363,210

3) I (180) 그 I에서만 뷰 2

[scrollView setContentOffset:CGPointMake(0, 180) animated:YES]; 

4 참조 할 Y

- (void)openModal{ 
UIViewController *viewController = [[UIViewController alloc] init]; 

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[btn setTitle:@"close" forState:UIControlStateNormal]; 
btn.frame = CGRectMake(10, 10, 100, 100); 
[viewController.view addSubview:btn]; 
[btn addTarget:self action:@selector(closePopOver) forControlEvents:UIControlEventTouchUpInside]; 


[self presentViewController:viewController animated:YES completion:nil]; 

}

5 '의 ViewController에 제가 ModalViewController을 열) 오프셋 콘텐츠 스크롤) ModalViewControllerscrollView의 내 레이아웃이 닫히지 않으면 설정하지 않은 다른 콘텐츠 오프셋으로 스크롤됩니다. 콘텐츠 오프셋을 y 180으로 재설정하면 scrollview의 내용 크기가 잘못됩니다.

- (void)closeModal{ 
[self dismissViewControllerAnimated:YES completion:^{ 

}]; 

}

나는 누군가가 나에게이 문제를 해결하는 데 도움이 될 수 있기를 바랍니다.

답변

3

:

이 방법은 지정된 뷰 컨트롤러에 presentedViewController 속성을 설정, 은 뷰 컨트롤러의 뷰 크기를 조정 한 다음 뷰 계층에보기를 추가합니다. 뷰는 제공된 뷰 컨트롤러의 modalTransitionStyle 속성에 지정된 전환 스타일에 따라 화면에 애니메이션으로 표시됩니다.

그래서보기 컨트롤러의 크기 조정이 의도됩니다. 어쨌든, 애플에 의해.

한 가지 방법은 크기가 조정 된 뷰의 좌표를 로깅하고 정확히 무엇이 변경되었는지 추측하는 것입니다. 어쩌면 이것을 방지하기 위해 제약 조건을 조정할 수 있습니다.

또는이 메서드의 완료 핸들러에서 모든 내용의 크기를 조정할 수 있습니다.

3

아마도 viewWillAppear에서 콘텐츠 오프셋을 재설정 할 수 있습니까? 그리고 이미 -(void)layoutsubviews을 구현 했습니까? UIViewControllerpresentViewController: 방법의 문서에서

+0

이것은 내 첫 번째 생각은 viewWill에있는 contentoffset을 다시 설정하는 것입니다. 그러나 나는 180으로 contentoffset을 설정하면 작동하지 않을 것입니다. – Zeropointer

+0

(void) layoutSubviews가 ViewController에서 작동하지 않습니다. – Zeropointer

+0

네 말이 맞아, 미안해. layoutsubviews를 사용하여 사용자 정의 UIView를 만들고 더 잘 작동하는지 확인할 수도 있지만. 개인적으로 항상 그렇게하고 싶습니다. 어쨌든, 당신이 보여주고있는 진짜 팝 오버입니까? 이 메서드는 openPopOver라고했기 때문에 popovercontroller에 대한 코드가 표시되지 않습니까? –

6

이것은 iOS autolayout wrt UIScrollViews의 버그 일 수 있다고 생각합니다. 내 경우에만 비슷한 문제가 있었는데, 자세히보기로 밀어 넣은 다음 UIScrollView 인 마스터보기로 다시 팝했습니다. 스크롤 뷰의 내용이 위로 이동합니다. 스크롤보기를 맨 위로 스크롤 한 다음 밀어 넣기를하고 다시 팝업하면 모든 것이 올바르게 재설정됩니다.

테이블 뷰 대신 마스터로 UIScrollView를 사용하여 일반 상자 세부 정보 응용 프로그램을 일반 텍스트로 시도해보고 결함을 입증 할 수있었습니다.

테이블 뷰 및 컬렉션 뷰에는이 문제가없는 것 같습니다.

+0

과 똑같은 문제가 발생했습니다. – Maurizio

+1

iOS의 실제 버그입니다. http://openradar.appspot.com/radar?id=2932404 – phatmann