【问题标题】:Extra UINavigationBar showing in iOS?在 iOS 中显示额外的 UINavigationBar?
【发布时间】:2015-08-06 12:34:50
【问题描述】:

我遇到了 UINavigationBar 的问题,当我在那里添加 UIButton 并运行应用程序时,我可以在 UINavigationBar 顶部看到一个额外的 UINaviagtionBar 叠加层。

请帮忙

结构是这样的

UITabbarController -> UINavigationController -->UIViewController

我已附上截图链接

运行时间[![[1]][1]][1]

Xcode

[navigationcontroller->viewcontroller 屏幕][3]

代码

ViewDidAppear()

UIImage *myImage = [UIImage imageNamed:@"filter.png"];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setImage:myImage forState:UIControlStateNormal];
myButton.showsTouchWhenHighlighted = YES;
myButton.frame = CGRectMake(0.0, 0.0,25,25);
[myButton addTarget:self action:@selector(refreshSection) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:myButton];
self.navigationItem.leftBarButtonItem = rightButton;

UIImage *myImage1 = [UIImage imageNamed:@"Contacts.png"];
UIButton *myButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton1 setImage:myImage1 forState:UIControlStateNormal];
myButton1.showsTouchWhenHighlighted = YES;
myButton1.frame = CGRectMake(0.0, 0.0,30,30);

[myButton1 addTarget:self action:@selector(profile) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *rightButton1 = [[UIBarButtonItem alloc] initWithCustomView:myButton1];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:rightButton1, nil]];

full screen storyboard

【问题讨论】:

  • 请发布您的 xcode 项目的更好的屏幕截图。您是否将视图控制器嵌入到导航控制器中?还是您手动将导航栏添加到 View 控制器中?
  • 是的,嵌入了导航控制器
  • 看看这个帖子有没有帮助:stackoverflow.com/questions/11199227/…
  • 好的,让我检查一下

标签: ios objective-c uinavigationcontroller uibutton uinavigationbar


【解决方案1】:

我认为代码是正确的,只需设置 contentMode 属性。

[[myButton imageView] setContentMode: UIViewContentModeScaleAspectFit];

其他按钮也一样。

【讨论】:

  • 不,我可以在现有栏的顶部看到一个更透明的 uinavigationbar
  • 添加[[UINavigationBar外观] setTranslucent:NO];在 applicationDidfinshLaunchingWithOption
  • 但是 UITababrController 和 UINavigationController 不是通过代码添加到 Storyboard 中的
  • 在你的代码之后,我可以在我的 uinavigationbar 下方看到黑色
【解决方案2】:

转到您的根导航控制器,选择导航栏并在属性检查器下,确保您有:

  1. 默认样式,
  2. 半透明选项已启用,
  3. 默认条形色调。

【讨论】:

  • 我会在这里给你我的故事板完整图像..请帮助我
  • 我需要使用这段代码 [self.navigationController pushViewController:health animated:YES];所以我需要一个嵌入的 UINavigationController
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-03
相关资源
最近更新 更多