在UINavigationController的UINavigationBar内部或顶部显示UIProgressView [英] Showing a UIProgressView inside or on top of a UINavigationController's UINavigationBar

查看:122
本文介绍了在UINavigationController的UINavigationBar内部或顶部显示UIProgressView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个UIProgressView来显示导航栏底部的进度(就像在iOS 7中发送iMessage或短信一样)。
但我在导航控制器的每个表视图视图中都需要这一点。
所以对我来说很清楚:我必须将它添加到UINavigationController中。
但问题是,不可能将UIProgressView添加到UINavigationController。
所以我尝试了两件事:

I want to have an UIProgressView to show a progress on the bottom of a navigation bar (just like when sending an iMessage or text message in iOS 7). But I need this consistently on every table view view of my navigation controller. So for me it was clear: I have to add this to the UINavigationController. But the problem is, it's not possible to add an UIProgressView to the UINavigationController. So I tried out two things:

第一次我试图以编程方式将它添加到UINavigationController的视图中。但问题是定位UIProgressView并使其在更改设备旋转时看起来很好。

1st I tried to add it to UINavigationController's view programmatically. But the problem was to position the UIProgressView and to make it look good when changing device rotation.

我尝试的第二件事是将UIProgressView添加到每个UITableView,但随后我真的必须为每个视图做这个。它也不好看,因为它不在导航栏的顶部,而是在它下面。但是我不喜欢第二种解决方案的主要原因是因为ProgressViews带有他们的TableView,所以你没有静态的,而是改变它们。

The 2nd thing I tried is to add the UIProgressView to every UITableView, but then I really have to do this for every view. Also it doesn't look good, because it is not on top of the navigation bar but beneath it. But the main reason why I didn't like the 2nd solution is because the ProgressViews go and come with their TableView, so you don't have a static one but changing ones.

在此之后,我不知道这样做,所以我问你......有没有人知道怎么做?

After this, I don't have any idea to do this, so I ask you… does anyone have an idea how to do this?

这是怎么回事看起来像:

That's how it should look like:

推荐答案

我终于找到了解决方案:

I finally found a solution:

我制作了一个自定义的UINavigationController并将其添加到 viewDidLoad

I made a custom UINavigationController and added this to viewDidLoad

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    progress = [[UIProgressView alloc] init];

    [[self view] addSubview:progress];

    UIView *navBar = [self navigationBar];


    [[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[navBar]-[progress(2@20)]"
                                                                        options:NSLayoutFormatDirectionLeadingToTrailing
                                                                        metrics:nil
                                                                          views:NSDictionaryOfVariableBindings(progress, navBar)]];

    [[self view] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[progress]|"
                                                                        options:NSLayoutFormatDirectionLeadingToTrailing
                                                                        metrics:nil
                                                                          views:NSDictionaryOfVariableBindings(progress)]];

    [progress setTranslatesAutoresizingMaskIntoConstraints:NO];

    [progress setProgress:0 animated:NO];
}

我创建了一个新的UIProgressView(我在中声明了@接口)添加了约束以将其定位在导航栏下方(这一步很重要:)设置 translatesAutoresizingMaskIntoConstraints

I created a new UIProgressView (I declared in @interface) added the constraints to position it beneath the navigation bar and (this step is important:) set translatesAutoresizingMaskIntoConstraints to NO.

这篇关于在UINavigationController的UINavigationBar内部或顶部显示UIProgressView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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