【问题标题】:IOS: pageViewController interface orientationIOS:pageViewController界面方向
【发布时间】:2015-07-10 18:06:21
【问题描述】:

我用代码创建它:

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 中仅启用横向?

【问题讨论】:

    标签: ios iphone uiviewcontroller uipageviewcontroller uiinterfaceorientation


    【解决方案1】:

    尝试使用此代码

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

    【讨论】:

      猜你喜欢
      • 2012-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多