2013-12-20 4 views
8

Я использую UIPageViewController для отображения изображений, встроенных в контроллеры дочерних элементов.Горизонтальная прокладка между контроллерами дочерних представлений UIPageViewController

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]; 

Все работает отлично, но я ненавижу, что контроллеры детского вида находятся рядом друг с другом.

enter image description here

мне было интересно, если есть способ, чтобы добавить отступы между контроллерами зрения ребенка так, чтобы путь они не рядом друг с другом.

Что-то, что будет выглядеть как этот:

enter image description here

ответ

13

проверки метода UIPageViewController инициализации

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

вы можете передать среди значение страницы пространства для opt в UIPageViewControllerOptionInterPageSpacingKey

7

Выберите UIPageViewController из раскадровку. Внутри инспектора атрибутов есть опция для установки Page Spacing.

5

С помощью Swift вы должны использовать инициализатор initWithTransitionStyle:navigationOrientation:options: и передать значение UIPageViewControllerOptionInterPageSpacingKey в свой options параметр, чтобы установить расстояние между страницами.

В качестве примера, следующий код показывает, как реализовать его с Swift 2.2:

let optionsDict = [UIPageViewControllerOptionInterPageSpacingKey : 20] 

let pageViewController = UIPageViewController(transitionStyle: .Scroll, 
    navigationOrientation: .Horizontal, 
    options: optionsDict) 

Обратите внимание, что UIPageViewController class reference заявляет о UIPageViewControllerOptionInterPageSpacingKey:

Значение должно быть CGFloat обернуты в экземпляр NSNumber.

Однако также работает словарь типа [String : Int], как показано в предыдущем коде.

Смежные вопросы