0

我的代碼創建:IOS:pageViewController接口方向

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

嘗試使用此代碼

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    if (self.isLandscapeOK) { 
     // for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown 
     return UIInterfaceOrientationMaskAll; 
    } 
    return UIInterfaceOrientationMaskPortrait; 
}