UINavigationItem提示问题 [英] UINavigationItem Prompt Issue

查看:133
本文介绍了UINavigationItem提示问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对UINavigationItem的提示有问题,我无法解决...

I'm having a problem with the prompt on a UINavigationItem that I just can't resolve...

我有一个主控制器和一个详细视图控制器。当我从主服务器推送到详细信息时,详细信息视图控制器上会显示一个提示:

I have a master and a detail view controller. When I push from the master to the detail a prompt is shown on the detail view controller:

但是,当我弹回主视图控制器时,视图不会调整大小并且窗口会显示(窗口已涂成红色):

However, when I pop back to the master view controller, the view isn't resized and the window shows through (the window has been coloured red):

这只发生在iOS7上,在iOS6上,视图按预期调整大小。

This only happens on iOS7, on iOS6 the view resizes as expected.

我试过几个例如在 viewWillDisappear viewDidDisappear 中将提示设置为nil,但似乎没有任何修复方法。

I've tried a few things such as setting the prompt to nil in viewWillDisappear or viewDidDisappear but nothing seems to fix it.

如果我将导航控制器中的导航栏设置为半透明,它确实解决了这个问题 - 不幸的是,这不是一个选项。

If I set the navigation bar in the navigation controller to translucent it does fix this - unfortunately that's not an option.

我'我在这里创建了一个非常小的示例项目,它演示了这个问题: ht tps://github.com/InsertWittyName/NavigationItemPrompt

I've created a very small example project here which demonstrates the issue: https://github.com/InsertWittyName/NavigationItemPrompt

提前感谢您的帮助!

推荐答案

我能想到的解决方案是继承master的 UIView ,并实现 viewDidMoveToSuperview 将视图的框架设置为从导航栏的高度到超级视图的结尾。由于导航栏不是半透明的,因此您的工作更容易,因为您不必考虑布局指南和内容插入内容。

A solution I can think of is to subclass the UIView of the master, and implement viewDidMoveToSuperview to set the frame of the view to be from the navigation bar's height to the end of the superview. Since the navigation bar is not translucent, your job is easier, as you don't have to take into account layout guides and content insets.

需要注意的一些事项。当推动和弹出时,系统将视图控制器的视图移动到动画的另一个超视图中,然后将其返回到导航控制器的私有视图层次结构。此外,当视图超出视图层次结构时,超级视图变为 nil

A few things to notice. When pushing and popping, the system moves your view controller's view into another superview for the animation and then returns it to the navigation controller's private view hierarchy. Also, when a view goes outside of the view hierarchy, the superview becomes nil.

这是一个示例实现:

@interface LNView : UIView

@end

@implementation LNView

- (void)viewDidMoveToSuperview
{
    [super viewDidMoveToSuperview];

    if(self.superview != nil)
    {
        CGRect rect = self.superview.bounds;

        rect.origin.y += 44;
        rect.size.height -= 44;

        [self setFrame:rect];
    }
}

@end

这个不是一个完美的实现,因为它使用硬编码值导航栏的高度,不考虑可能的工具栏等。但所有这些你可以作为属性添加到此视图和 viewDidLoad ,在开始进入视图层次结构之前,根据您的需要设置参数。

This is not a perfect implementation because it uses a hardcoded value for the navigation bar's height, does not take into account a possible toolbar, etc. But all these you can add as properties to this view and in viewDidLoad, before it starts going into the view hierarchy, set the parameters according to your needs.

这篇关于UINavigationItem提示问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆