IOS:pageViewController界面方向
Posted
技术标签:
【中文标题】IOS:pageViewController界面方向【英文标题】:IOS: pageViewController interface orientation 【发布时间】: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 中仅启用横向?
【问题讨论】:
【参考方案1】:尝试使用此代码
- (BOOL)shouldAutorotate
return YES;
- (NSUInteger)supportedInterfaceOrientations
if (self.isLandscapeOK)
// for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
return UIInterfaceOrientationMaskAll;
return UIInterfaceOrientationMaskPortrait;
【讨论】:
以上是关于IOS:pageViewController界面方向的主要内容,如果未能解决你的问题,请参考以下文章
IOS:通过PageViewController显示WebView
滚动视图内的pageviewcontroller内的iOS tableview
iOS/Swift/Storyboard:仅使用屏幕的 *part* 添加 PageViewController?