Проблема с автоматическим расположением iOS в ScrollView

Здравствуйте, у меня есть проблема с автоматической разметкойUIScrollView а такжеModalViewController, Вот мои шаги кодирования в качестве примера кода:

1) у меня естьUIViewController сUIScrollView какsubView

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]];

это работает

2) я добавляю 2 подпункта кscrollView

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];

это тоже хорошо работает

3) Я прокручиваю содержимое со смещением y 180, чтобы видеть только view2

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

4) Я открываюModalViewController на `ViewController}

- (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) когда я закрываюModalViewController мой макет наscrollView А не было»т работает он прокручивает к другому содержанию смещения, которое я не установил. Когда я сбрасываю смещение содержимого на y 180, размер содержимого прокрутки отображается неправильно.}

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

}];

Я надеюсь, что кто-то может помочь мне решить эту проблему.

Ответы на вопрос(3)

Ваш ответ на вопрос