안녕하세요, UIScrollView
및 ModalViewController
의 자동 레이아웃 문제가 있습니다.iOS AutoLayout ScrollView 문제
1) 나는 내가 scrollView
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,2103) 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
을 열) 오프셋 콘텐츠 스크롤) ModalViewController
scrollView
의 내 레이아웃이 닫히지 않으면 설정하지 않은 다른 콘텐츠 오프셋으로 스크롤됩니다. 콘텐츠 오프셋을 y 180으로 재설정하면 scrollview의 내용 크기가 잘못됩니다.
- (void)closeModal{
[self dismissViewControllerAnimated:YES completion:^{
}];
}
나는 누군가가 나에게이 문제를 해결하는 데 도움이 될 수 있기를 바랍니다.
이것은 내 첫 번째 생각은 viewWill에있는 contentoffset을 다시 설정하는 것입니다. 그러나 나는 180으로 contentoffset을 설정하면 작동하지 않을 것입니다. – Zeropointer
(void) layoutSubviews가 ViewController에서 작동하지 않습니다. – Zeropointer
네 말이 맞아, 미안해. layoutsubviews를 사용하여 사용자 정의 UIView를 만들고 더 잘 작동하는지 확인할 수도 있지만. 개인적으로 항상 그렇게하고 싶습니다. 어쨌든, 당신이 보여주고있는 진짜 팝 오버입니까? 이 메서드는 openPopOver라고했기 때문에 popovercontroller에 대한 코드가 표시되지 않습니까? –