Axo*_*ort 42 uinavigationbar uitoolbar uistoryboard ios7
将导航栏或工具栏(故事板)拖动到视图控制器时出现问题.
UINavigationBar的:

如上图所示,右侧按钮几乎与状态栏重叠.
使用UIToolbar它会发生相同的事情:

这个视图控制器旨在用作模态,这就是我没有使用UINavigationController的原因.
在另一节我使用UINavigationController,它看起来像我期望的那样:

如何在不重叠状态栏的情况下将UINavigationBar/UIToolbar拖动到视图控制器?
Leo*_*ica 48
导航栏或工具栏必须为(0,viewController.topLayoutGuide.length),条形位置为UIBarPositionTopAttached.您应该将导航栏或工具栏的代理设置为视图控制器,然后返回UIBarPositionTopAttached.如果定位正确,您将在第三张图像中得到结果.
更多信息:https: //developer.apple.com/documentation/uikit/uibarpositioningdelegate?language = objc
onm*_*133 25
做这些步骤
将NavigationBar拖动到Xib中的ViewController,将ViewController设置为其委托.请注意,NavigationBar应位于(0,20)
在ViewController中,符合 UINavigationBarDelegate
@interface ETPViewController () <UINavigationBarDelegate>
Run Code Online (Sandbox Code Playgroud)
实现此方法
- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar
{
return UIBarPositionTopAttached;
}
Run Code Online (Sandbox Code Playgroud)
positionForBar告诉NavigationBar它是否应该将其背景向上扩展到状态栏
bob*_*ics 10
请在此处查看我的答案,为方便起见,我复制了以下内容:
我发现最简单的解决方法是将要显示的视图控制器包装在导航控制器中,然后显示该导航控制器.
MyViewController *vc = [MyViewController new];
UINavigationController *nav = [[UINavigationController alloc]
initWithRootViewController:vc];
[self presentViewController:nav animated:YES completion:NULL];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
35463 次 |
| 最近记录: |