我用代码创建它:
self.pageViewController = [[PageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:@{ UIPageViewControllerOptionInterPageSpacingKey : @30 }];
self.pageViewController.delegate = self;
self.pageViewController.dataSource = self;
self.pageViewController.automaticallyAdjustsScrollViewInsets = NO;
self.currentMediaPlayerViewController = [self createMediaPlayerViewControllerWithMediaItem:self.mediaItems[self.pageIndex]];
NSArray *pageViewControllers = @[self.currentMediaPlayerViewController];
[self.pageViewController setViewControllers:pageViewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
[self addChildViewController:self.pageViewController];
[self.pageViewController didMoveToParentViewController:self];
[self.view addSubview:self.pageViewController.view];
我只启用parentVC中的横向方向到pageViewController。但仍然可以抓住轮换。
- (void)viewDidLoad
{
self.navigationController.delegate = self;
NSNumber *value = @(UIInterfaceOrientationLandscapeLeft);
NSString *keyOrientation = @"orientation";
if (![value isEqualToNumber:@((NSInteger)[[UIDevice currentDevice] valueForKey:keyOrientation])]) {
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
- (NSUInteger)navigationControllerSupportedInterfaceOrientations: (UINavigationController *)navigationController
{
return UIInterfaceOrientationMaskLandscape;
如何在pageViewController中仅启用横向?
答案 0 :(得分:0)
尝试使用此代码
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
if (self.isLandscapeOK) {
// for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}