HMSegment使用记录

  • (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];
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容