UIPageViewController 和景观

发布于 2025-01-04 08:30:45 字数 969 浏览 3 评论 0原文

我一直在尝试以下操作,但没有任何效果,

NSDictionary *pageViewOptions = [NSDictionary dictionaryWithObjectsAndKeys:UIPageViewControllerOptionSpineLocationKey, [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMid],nil];
NSLog(@"pageViewOptions :%@",pageViewOptions);    

self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:pageViewOptions];    
NSLog(@"spineLocation :%d",self.pageViewController.spineLocation);

pageViewOptions 处的 NSlog 为 2,spineLocation 处的 NSlog 为 1。这让我陷入困境,我想做的就是在中间使用脊柱进行初始化。它总是在左侧初始化。该应用程序在横向模式下初始化,但仅在将设备旋转 180 度后才执行该方法 “- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spinLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation” 有效,然后我的脊柱就在中间了。有人可以解释一下吗?我到处寻找答案。

我想要它做的就是在横向中初始化,中间有一个脊柱

I have been trying the following and nothing is working

NSDictionary *pageViewOptions = [NSDictionary dictionaryWithObjectsAndKeys:UIPageViewControllerOptionSpineLocationKey, [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMid],nil];
NSLog(@"pageViewOptions :%@",pageViewOptions);    

self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:pageViewOptions];    
NSLog(@"spineLocation :%d",self.pageViewController.spineLocation);

the NSlog at pageViewOptions is 2, NSlog at spineLocation is 1. This is driving me up the wall, all i want to do is initialise with spine in the middle. It always initialises on the left. the app is initialised in landscape but only after rotating the device 180 degrees the method
"- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation"
works and then i get spine in the middle. could someone please shed some light on this. I've searched everywhere for an answer.

all i want it to do is initialise in landscape with a spine in the middle

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

客…行舟 2025-01-11 08:30:45

尝试使用“options”参数:

NSDictionary *options = (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) ? [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMid] forKey: UIPageViewControllerOptionSpineLocationKey] : nil; 

self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options];

...

并且不要忘记初始化 2 个内容视图控制器:

NSArray *viewControllers = [NSArray arrayWithObjects:contentViewController1, contentViewController2, nil];

[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

Try to use "options" parameter:

NSDictionary *options = (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) ? [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMid] forKey: UIPageViewControllerOptionSpineLocationKey] : nil; 

self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options];

...

And don't forget to initialize 2 content view controllers:

NSArray *viewControllers = [NSArray arrayWithObjects:contentViewController1, contentViewController2, nil];

[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文