2

我整个下午都被这个问题困住了。我制作了一个自定义 UIViewController。到目前为止,我在这个自定义视图控制器中显示了自定义视图。一切都好。现在我想做的是在自定义控制器中显示一个 pageviewcontroller。没有错误,但是页面控制器的视图显示在自定义控制器(.

这是我的代码

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

这是界面(非常简单):

@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 :

CGRect pageViewRect = self.view.bounds;
pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
self.pager.view.frame = pageViewRect;
[self.pager didMoveToParentViewController:self];

但没有运气,如图所示: 自定义视图控制器位于日历视图下方。 日历视图应该在自定义视图控制器内部而不是外部

自定义视图控制器位于日历视图下方。日历视图应该在自定义视图控制器内部而不是外部。此外,我怎样才能把脊椎放在上面?

[已解决] 没关系:第一个答案是正确的。我的错误是错误的框架设置。

4

1 回答 1

2

我有同样的问题。在调用之前设置页面视图控制器的框架didMoveToParentViewController:应该可以解决它。

于 2013-07-11T15:14:02.937 回答