我的页面视图控制器的页面指示器将我的视图的其余部分向上推,而不是在它之上。如何在视图上方分层?
编辑:我附上了正在发生的事情和代码的图片。
#import "RootViewController.h"
#import "PageViewController.h"
#import "AViewController.h"
#import "BViewController.h"
#import "CViewController.h"
@interface RootViewController () <UIPageViewControllerDataSource>
@property (strong, nonatomic) UIPageViewController *pageViewController;
@property (strong, nonatomic) AViewController *aViewController;
@property (strong, nonatomic) BViewController *bViewController;
@property (strong, nonatomic) CViewController *cViewController;
@end
@implementation RootViewController
@synthesize pageViewController;
@synthesize aViewController;
@synthesize bViewController;
@synthesize cViewController;
- (void)viewDidLoad
{
[super viewDidLoad];
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 480)
{
UIStoryboard *iPhoneStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
aViewController = [iPhoneStoryboard instantiateViewControllerWithIdentifier:@"AViewController"];
bViewController = [iPhoneStoryboard instantiateViewControllerWithIdentifier:@"BViewController"];
cViewController = [iPhoneStoryboard instantiateViewControllerWithIdentifier:@"CViewController"];
}
if (iOSDeviceScreenSize.height == 568)
{
UIStoryboard *iPhone5Storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone5" bundle:nil];
aViewController = [iPhone5Storyboard instantiateViewControllerWithIdentifier:@"AViewController"];
bViewController = [iPhone5Storyboard instantiateViewControllerWithIdentifier:@"BViewController"];
cViewController = [iPhone5Storyboard instantiateViewControllerWithIdentifier:@"CViewController"];
}
pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
pageViewController.dataSource = self;
[[pageViewController view] setFrame:CGRectMake(0, 0, 320, iOSDeviceScreenSize.height)];
AViewController *initialViewController = (BViewController *)[self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:pageViewController];
[[self view] addSubview:[pageViewController view]];
[pageViewController didMoveToParentViewController:self];
}
#pragma mark - PageViewController Data Source
- (UIViewController *)viewControllerAtIndex:(NSUInteger)index
{
PageViewController *viewController;
if (index == 0)
{
viewController = aViewController;
}
else if (index == 1)
{
viewController = bViewController;
}
else
{
viewController = cViewController;
}
viewController.index = index;
return viewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = [(PageViewController *)viewController index];
if (index == 0)
return nil;
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [(PageViewController *)viewController index];
index++;
if (index == 3)
return nil;
return [self viewControllerAtIndex:index];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return 3;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
@end