我有定位,自动布局在屏幕上一个UILabel,但是当我隐藏导航栏,它会导致标签"抽搐"用于第二 [英] I have a UILabel positioned on the screen with autolayout, but when I hide the navigation bar it causes the label to "twitch" for a second

查看:203
本文介绍了我有定位,自动布局在屏幕上一个UILabel,但是当我隐藏导航栏,它会导致标签"抽搐"用于第二的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

项目: http://cl.ly/1T2K0V3w1P21

,最好通过项目看出,这是一个小的下载剥离下来,只是视图控制器。

It's best seen through the project, it's a small download stripped down to just the view controller.

基本上,我的UILabel停留在完美的位置自动布局,但是当我隐藏导航栏,(你可以在任何地方通过点击屏幕为此项目)是导致它抽搐。我如何使它因此它停留在相同的位置,而不管发生了什么事情的导航栏?

Basically, my UILabel stays in place perfectly with auto layout, but when I hide the navigation bar (you can do this in the project by tapping the screen anywhere) it causes it to twitch. How do I make it so it stays in the exact same position regardless of what's going on with the navigation bar?

它似乎正呈现动画(我想)会导致自动版式感到困惑。

It seems that it being animated (which I want) causes AutoLayout to get confused.

下面是标签上的限制是什么样子:

Here's what the constraints on the label look like:

任何人都可以提供一些建议,以什么我做错了?

Could anyone offer some advice as to what I'm doing wrong?

推荐答案

,你可以尝试从标签(这是22中的常数)定义了顶部空间限制到上海华,进行连接一个IBOutlet到您的视图属性,它的动画时,导航栏隐藏或显示。

Instead of bottom space constraint, you can try to define the top space constraint to the superview from the label (which is 22 in the constant), connect it as an IBOutlet to your view property, and animate it when the navigation bar is hidden or shown.

例如,我宣布顶部空间属性作为topSpaceConstraint:

For example, I declare the top space property as topSpaceConstraint:

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpaceConstraint;

然后hideControls方法里面,我可以动画约束:

Then inside the hideControls method, I can animate the constraint:

- (void)hideControls:(BOOL)visible {
    if (visible) {
        [UIView animateWithDuration:UINavigationControllerHideShowBarDuration animations:^{
            self.topSpaceConstraint.constant = 66; //44 is the navigation bar height, you need to find a way not to hardcode this
            [self.view layoutIfNeeded];
        }];     
    }
    else {
        [UIView animateWithDuration:UINavigationControllerHideShowBarDuration animations:^{
            self.topSpaceConstraint.constant = 22;
            [self.view layoutIfNeeded];
        }];
    }
    [self.navigationController setNavigationBarHidden:visible animated:YES];
    self.backFiftyWordsButton.hidden = visible;
    self.forwardFiftyWordsButton.hidden = visible;
    self.WPMLabel.hidden = visible;
    self.timeRemainingLabel.hidden = visible;
}

这篇关于我有定位,自动布局在屏幕上一个UILabel,但是当我隐藏导航栏,它会导致标签"抽搐"用于第二的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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