【问题标题】:UISegmentControl as NavigationControllerUISegmentedControl 作为导航控制器
【发布时间】:2013-01-30 19:16:12
【问题描述】:

我正在尝试制作一些自定义视图,我想知道如何实现这样的东西,你有一个 UISegmentControl(或类似的东西),你在不同的视图控制器之间切换,但段控制仍然在同一个地方(不介意图片大小不同)。就像一个导航控制器,但有一个段而不是它。任何想法将不胜感激。谢谢

【问题讨论】:

  • 我已经为您提供了答案。但是,如果您仍然感到困惑,请告诉我...我会为您提供更简化的答案。
  • 嘿,你的问题解决了吗???如果是,请点赞我的回答并接受我的回答,如果否,请说出您的疑问。

标签: ios uiviewcontroller uinavigationcontroller uisegmentedcontrol


【解决方案1】:

这很容易做到。您只需要使用导航控制器,但隐藏所有视图上的导航栏。然后你可以使用

[self.navigationController pushViewController:@"Your viewController to which you want to navigate" animated:YES];

在选择段索引上。而要从任何这些视图控制器返回,您只需要实现这个

[self.navigationController popViewControllerAnimated:YES]; 在选定段索引的按钮操作上。我希望这会对你有所帮助。编码快乐..!!!

【讨论】:

  • 如果我将 UISegmentControl 设为导航栏的子项并将其隐藏,则导航栏和段控件都将被隐藏:)
  • 使导航栏的颜色透明并禁用导航栏....希望你的目的能达到。
  • 您的解决方案意味着将 UISegmentControl 设置为 UINavigationController 的子级,然后将导航控制器的 alpha 更改为 0.0,这也会使该段透明。我努力了。它不起作用
  • 我不是告诉你让段控制透明...只做透明导航栏..并尝试将段控制放在导航栏下方,这样它就不会受到导航的影响酒吧的透明度..
  • 好的,但是一旦我推送了下一个视图控制器的视图,它将没有段控制器,因为它只在一个视图控制器中。
【解决方案2】:

您可以使用段控制和数组创建 ViewController,其中将包含其他控制器。 在段更改时,您应该从数组中的一个控制器查看视图,并将其像子视图一样添加到父 ViewControllerView。 这看起来像这样

//in ViewControllerView.m
-(void)touchUpInsideSegmentIndex:(NSUInteger)segmentIndex {
   //delegate is your ViewController
    UIView * newToolView = [delegate viewAtIndex:segmentIndex];
    //contentView declared in ViewControllerView.h
    if (newToolView != contentView && newToolView) {
        [contentView removeFromSuperview];
        [contentView release];
        contentView = [newToolView retain];
        [self addSubview:contentView];
        [self setNeedsLayout];
    }
}

//in ViewController.m
- (UIView*)viewAtIndex:(NSInteger)index {
    //yourControllersArray is an array of your controllers
    if (index < 0 || index >= [yourControllersArray count]) {       
        NSLog(@"View At Wrong Index %d (max=%d)", index, [yourControllersArray count]);
        return nil;
    }
    return [[yourControllersArray objectAtIndex: index] view];
}

【讨论】:

    【解决方案3】:
    1. 在导航栏中定位 UISegmentedControl。
    2. 设置导航栏透明。
    3. 在 UISegmentedControl 方法中,从 UINavigationController 堆栈推送和弹出视图控制器,或者显示和关闭模式

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      • 2017-05-14
      • 1970-01-01
      • 2014-01-26
      相关资源
      最近更新 更多