本文介绍了UIPageViewController子视图控制器之间的水平填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIPageViewController来显示嵌入在子视图控制器中的图像。

  NSDictionary * options = [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey:UIPageViewControllerOptionSpineLocationKey]; 
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizo​​ntal options:options];
self.pageViewController.dataSource = self;
self.pageViewController.view.frame = self.view.bounds;

ImageViewController * initialViewController = [self viewControllerAtIndex:0];
initialViewController.index = 0;

NSArray * viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageViewController setViewControllers:viewControllers方向:UIPageViewControllerNavigationDirectionForward动画:NO completion:nil];

[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];

一切都很好但我讨厌儿童视图控制器彼此相邻。





我想知道是否有办法在子视图控制器之间添加填充,这样它们就不会彼此相邻。



看起来更像这样的东西



解决方案

检查UIPageViewController初始化方法



- (id)initWithTransitionStyle:(UIPageViewControllerTransitionStyle)样式navigationOrientation:(UIPageViewControllerNavigationOrientation)navigationOrientation选项:(NSDictionary *)opt



您可以在 UIPageViewControllerOptionInterPageSpacingKey opt >

I am using UIPageViewController to display images that are embedded in child view controllers.

NSDictionary *options = [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey: UIPageViewControllerOptionSpineLocationKey];
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options: options];
self.pageViewController.dataSource = self;
self.pageViewController.view.frame = self.view.bounds;

ImageViewController *initialViewController = [self viewControllerAtIndex:0];
initialViewController.index = 0;

NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];

Everything works great but I hate that the child view controllers are right next to one another.

I was wondering if there was a way to add padding between the child view controllers so that way they're not right next to one another.

Something that would look more like this:

解决方案

check UIPageViewController init method

- (id)initWithTransitionStyle:(UIPageViewControllerTransitionStyle)style navigationOrientation:(UIPageViewControllerNavigationOrientation)navigationOrientation options:(NSDictionary *)opt

you can pass your inter page space value to opt in UIPageViewControllerOptionInterPageSpacingKey

这篇关于UIPageViewController子视图控制器之间的水平填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 02:22