自定义 UIViewController 中的 UIPageViewController [英] UIPageViewController inside a custom UIViewController
问题描述
我整个下午都被这个问题困住了.我做了一个自定义的 UIViewController.到目前为止,我在这个自定义视图控制器中显示了自定义视图.一切都很好.现在我想做的是在自定义控制器中显示一个 pageviewcontroller.没有错误,但是页面控制器的视图显示在自定义控制器的边界之外 (.
I am stucked with this problem for all the afternoon. I made a custom UIViewController. Up to now I shown custom views inside this custom viewcontroller. All fine. Now what I want to do is to show a pageviewcontroller inside the custom controller. No error, but the view of the pagecontroller is shown outside the bounds of the custom controller (.
这是我的代码
- (void)viewDidLoad
{
[super viewDidLoad];
self.monthYearController = [[avvAgendaMonthViewController alloc] init];
self.yearViewController = [[avvAgendaYearViewController alloc] init];
self.pager = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
//Assign the delegate and datasource .
self.pager.delegate = self;
self.pager.dataSource = self;
//Set the initial view controllers.
NSArray *viewControllers = [NSArray arrayWithObject:self.yearViewController];
[self.pager setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
//Add the pageViewController as the childViewController
[self addChildViewController:self.pager];
[self.view addSubview:self.pager.view];
[self.pager didMoveToParentViewController:self];
CGRect pageViewRect = self.view.bounds;
pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
self.pager.view.frame = pageViewRect;
//Assign the gestureRecognizers property of our pageViewController to our view's gestureRecognizers property.
self.view.gestureRecognizers = self.pager.gestureRecognizers;
这是界面(非常简单):
And here is the interface (very simple):
@interface CustomNavigatorViewController : UIViewController <CustomNavigationDelegate,UIPageViewControllerDataSource,UIPageViewControllerDelegate>
@property (nonatomic,strong) CustomNavigation* navigation;
@property (nonatomic,strong) UIPageViewController *pager;
@property (nonatomic,strong) AgendaYearViewController* yearViewController;
@property (nonatomic,strong) AgendaMonthViewController* monthYearController;
@property (nonatomic,strong) UIViewController* agendaCurrentView;
@end
我尝试(如第一个答案中所建议的)最后调用 didMoveToParentViewController:
I tried (as suggested in the first answer) to call didMoveToParentViewController at the end:
CGRect pageViewRect = self.view.bounds;
pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
self.pager.view.frame = pageViewRect;
[self.pager didMoveToParentViewController:self];
但没有运气,如图所示:
but no luck as the picture shows:
自定义视图控制器位于日历视图下方.日历视图应该在自定义视图控制器内部而不是外部.而且,我怎么才能把脊椎放在上面?
the custom view controller is underneath the calendar view. The calendar view should be inside the custom view controller and not outside. Moreover, how can I put the spine on the top?
[已解决]没关系:第一个答案是正确的.我的错误是框架设置错误.
[SOLVED] Never mind: the first answer was right. My mistake was a wrong frame set.
推荐答案
我遇到了完全相同的问题.在调用 didMoveToParentViewController:
之前设置页面视图控制器的框架应该可以解决它.
I had the exact same problem. Setting the frame of the page view controller before calling didMoveToParentViewController:
should resolve it.
这篇关于自定义 UIViewController 中的 UIPageViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!