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

查看:14
本文介绍了在 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?

它应该是这样的:

推荐答案

终于找到了解决办法:

我制作了一个自定义 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(我在 @interface 中声明)添加了约束以将其定位在导航栏下方并且(这一步很重要:)将 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天全站免登陆