-
(void)setupSegment
{
NSArray *array = @[@"部门",@"职位"];
[self.segment setSectionTitles:array];self.segment.borderType = HMSegmentedControlBorderTypeBottom;
self.segment.borderWidth = 0.5;self.title = @"部门管理";
// 添加子控制器
// MEDPBDepartmentCollectionViewController *department = [[MEDPBDepartmentCollectionViewController alloc] init];
[self addChildViewController:[[MEDPBDepartmentCollectionViewController alloc] init]];
// MEDPBPositionTableViewController *position = [[MEDPBPositionTableViewController alloc] init];
[self addChildViewController:[[MEDPBPositionTableViewController alloc] init]];// 默认页面
UIViewController *vc = [[self childViewControllers] objectAtIndex:0];
vc.view.frame = self.contentView.bounds;
[self.contentView addSubview:vc.view];// 绑定事件
[self.segment addTarget:self action:@selector(segmentClick:) forControlEvents:UIControlEventValueChanged];
} -
(void)segmentClick:(UISegmentedControl *)segment
{
NSInteger index = segment.selectedSegmentIndex;UIViewController *fromVC = nil;
for (UIViewController *vc in self.childViewControllers) {
if (vc.view.superview == self.contentView) {
fromVC = vc;
break;
}
}
UIViewController *toVC = [self.childViewControllers objectAtIndex:index];
if (fromVC != toVC) {
[self transitionFromViewController:fromVC toViewController:toVC duration:0.5 options:UIViewAnimationOptionCurveEaseInOut animations:NULL completion:NULL];
}
}
- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion
{
toViewController.view.frame = fromViewController.view.frame;
[super transitionFromViewController:fromViewController toViewController:toViewController duration:duration options:options animations:animations completion:completion];
}