Skip to main content
 首页 » 操作系统

ios之如何更改 UIPageViewControllerOptionInterPageSpacingKey 的值

2024年01月01日44bluestorm

我正在尝试在 ViewDidAppear() 中设置值 UIPageViewControllerOptionInterPageSpacingKey

但是我的UIPageViewController的初始化代码在ViewDidLoad()

如果我在 View 设置布局之前设置 UIPageViewControllerOptionInterPageSpacingKey,自动布局就会出现问题

请您参考如下方法:

您必须在初始化时更改页面间距。这可以在 XIB/Storyboard 中或使用 initWithTransitionStyle:navigationOrientation:options: 方法传递 @{UIPageViewControllerOptionInterPageSpacingKey : @(5.f)} 来完成。这在 UIPageViewController.h 文件中提到 from Apple :

// Key for specifying spacing between pages in options dictionary argument to initWithTransitionStyle:navigationOrientation:options:. 
// Value should be a CGFloat wrapped in an NSNumber. Default is '0'. 
// Only valid for use with page view controllers with transition style 'UIPageViewControllerTransitionStyleScroll'. 
UIKIT_EXTERN NSString * const UIPageViewControllerOptionInterPageSpacingKey NS_AVAILABLE_IOS(6_0);