一个界面,有多个滑动界面,然后用多个控制器控制这些滑动的界面
添加每个子控制器到主界面控制器
[self addChildViewControl];
- (void)addChildViewControl {
JHNewsViewController *newsVC = [[JHNewsViewController alloc] init];
newsVC.title = @"新闻";
[self addChildViewController:newsVC];
JHPersonnelViewController *personneVC = [[JHPersonnelViewController alloc] init];
[self addChildViewController:personneVC];
JHRemindViewController *remindVC = [[JHRemindViewController alloc] init];
[self addChildViewController:remindVC];
JHScheduleViewController *scheduleVC = [[JHScheduleViewController alloc] init];
[self addChildViewController:scheduleVC];
}
添加一个scrollView,然后把每个子控制器的视图添加到上面
- (void)setupContentScrollView {
UIScrollView *myScrollView = [[UIScrollView alloc] init];
myScrollView.showsHorizontalScrollIndicator = NO;
myScrollView.frame = CGRectMake(0, 64 + 50, ScreenWidth, ScreenHeigth - 64 - 50 - 50);
myScrollView.pagingEnabled = YES;
myScrollView.contentSize = CGSizeMake(self.childViewControllers.count * ScreenWidth, ScreenHeigth - 64 - 50 - 50);
myScrollView.delegate = self;
[self.view addSubview:myScrollView];
self.contentScrollView = myScrollView;
myScrollView.bounces = NO;
[self scrollViewDidEndScrollingAnimation:myScrollView];
JHNewsViewController *newsVC = self.childViewControllers[0];
newsVC.view.frame = CGRectMake(0, 0, ScreenWidth, myScrollView.mj_h);
[myScrollView addSubview:newsVC.view];
JHPersonnelViewController *personnelVC = self.childViewControllers[1];
personnelVC.view.frame = CGRectMake(ScreenWidth, 0, ScreenWidth, myScrollView.mj_h);
[myScrollView addSubview:personnelVC.view];
JHRemindViewController *remindVC = self.childViewControllers[2];
remindVC.view.frame = CGRectMake(ScreenWidth * 2, 0, ScreenWidth, myScrollView.mj_h);
[myScrollView addSubview:remindVC.view];
JHScheduleViewController *scheduleVC = self.childViewControllers[3];
scheduleVC.view.frame = CGRectMake(ScreenWidth * 3, 0, ScreenWidth, myScrollView.mj_h);
[myScrollView addSubview:scheduleVC.view];
}
ok,就是这么简单,每天进步一点点