我正在制作一个应用程序,我只想在父视图控制器中显示子视图控制器,即仅在父视图控制器的 3/4 部分。我已经实现了以下代码,但子视图控制器正在填充整个父视图控制器。
我的代码是:
- (CardsChildViewController *)viewControllerAtIndex:(NSUInteger)index {
CardsChildViewController *childViewController = [[CardsChildViewController alloc] initWithNibName:@"CardsChildViewController" bundle:nil];
childViewController.index = index;
return childViewController;
}
在 viewDidLoad 函数上我正在写:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
CardsChildViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
}
我通过以下方式的帮助做到了这一点:http: //www.appcoda.com/uipageviewcontroller-tutorial-intro/