1
我被這個問題困住了整個下午。 我做了一個自定義的UIViewController。到目前爲止,我在這個自定義視圖控制器中顯示了自定義視圖。一切都好。現在我想要做的是在自定義控制器中顯示一個pageviewcontroller。沒有錯誤,但的PageController的視圖顯示自定義控制器(邊界之外UIPageViewController在一個自定義的UIViewController裏面
這裏是我的代碼
- (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];
但沒有運氣,如圖所示:
自定義視圖控制器位於日曆視圖下方。日曆視圖應位於自定義視圖控制器內部,而不是外部。 此外,我怎樣才能把脊柱放在頂部?
[已解決] 沒關係:第一個答案是對的。我的錯誤是一個錯誤的框架集。
我試過但沒有運氣(見編輯的任務)。 – giuseppe