child を持つView ControllerをプログラムでセットアップしましたUIPageViewController
。これにより、プログラムでセットアップされた他のさまざまなView Controllerが表示されます。これらのビュー コントローラーのビューは にtranslatesAutoresizingMaskIntoConstraints
設定されてYES
いますが、ページ ビュー コントローラーのビューは制約を使用して、自分自身を最上位のビュー コントローラーに配置します。
問題は、ユーザーがデバイスを回転させると、ページ ビュー コントローラーはフレームのサイズを変更しますが、子ビュー コントローラーは変更しないことです。によってdidRotateFromInterfaceOrientation
、そのフレームはまだ古い方向からです。回転メソッドが子ビュー コントローラーで呼び出されることを確認しましたが、そのフレームは変更されません。
次のようにページ ビュー コントローラーを設定します。
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.view.backgroundColor = [UIColor clearColor];
self.pageViewController.view.translatesAutoresizingMaskIntoConstraints = NO;
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
[self.pageViewController willMoveToParentViewController:self];
[self.view addSubview:self.pageViewController.view];
[self addChildViewController:self.pageViewController];
[self.pageViewController didMoveToParentViewController:self];
self.currentPageIndex = 0;
self.currentPageController = [self pageForIndex:self.currentPageIndex];
self.currentPageController.delegate = self;
[self.pageViewController setViewControllers:@[self.currentPageController] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];
呼び出してみsetNeedsLayout
たのですが、回転アニメーションが不器用で、次にスワイプしたページのサイズも適切にリサイズされていません。
ページ ビュー コントローラーが子ビュー コントローラーのサイズを変更しないのはなぜですか? また、これを行うにはどうすればよいですか?
ありがとう!