自动布局的UIView上约束更改不会动画 [英] Auto Layout UIView on constraint change does not animate

查看:151
本文介绍了自动布局的UIView上约束更改不会动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是学动画与自动布局从教程

I was learning the auto layout with animations from the tutorial

<一个href=\"http://weblog.invasive$c$c.com/post/42362079291/auto-layout-and-core-animation-auto-layout-was\">http://weblog.invasive$c$c.com/post/42362079291/auto-layout-and-core-animation-auto-layout-was

和事情的工作完美。

当我想在我的应用程序中使用这个概念,试图从底部到顶部动画一个设置屏幕(一个UIView),它的伟大工程时,设置屏幕只是一个空的UIView,

When I tried to use this concept in my application, trying to animate a settings screen(a UIView) from bottom to top,it works great when the settings screen is just an empty UIView,

但在我的情况下添加一个UILabel作为一个子视图这个设置画面,动画只是消失。
在除去该形成的UILabel设置画面,动画是可见的。

But in case I add a UILabel as a subview to this settings screen, the animation just vanishes. On removing this UILabel form the settings screen, the animation is visible.

下面是我已连接插座

__weak IBOutlet UIView *settingsView;
__weak IBOutlet NSLayoutConstraint *settingsBottomConstraint;
__weak IBOutlet NSLayoutConstraint *settingsViewHeightConstraint;

查看做负载设置方法(setupViews)

View did load setup method(setupViews)

-(void)setupViews
{
    settingsBottomConstraint.constant = - settingsViewHeightConstraint.constant;
    [settingsView setNeedsUpdateConstraints];
    [settingsView layoutIfNeeded];
    isSettingsHidden = YES;
}

隐藏/取消隐藏方法

Hide/Unhide Method

- (IBAction)showSettingsScreen:(id)sender {

    if (isSettingsHidden) {

        settingsBottomConstraint.constant = 0;
        [settingsView setNeedsUpdateConstraints];
        [UIView animateWithDuration:.3 animations:^{
            [settingsView layoutIfNeeded];
        }];
    }
    else{

        settingsBottomConstraint.constant = - settingsViewHeightConstraint.constant;
        [settingsView setNeedsUpdateConstraints];
        [UIView animateWithDuration:0.3 animations:^{
            [settingsView layoutIfNeeded];
        }];

    }
    isSettingsHidden = !isSettingsHidden;
}

我的问题似乎相似
问题与UIView的自动布局动画

推荐答案

我找到了答案。

相反的,

[settingsView layoutIfNeeded];

这行做它的工作般的魅力,

this line made it worked like charm,

[self.view layoutIfNeeded];

我想我们需要在父视图不只是我们试图以动画视图执行layoutIfNeeded方法。

I suppose we need to perform layoutIfNeeded method on the parent view not just the view we are trying to animate.

更新:
作为由codyko评论指出,这仅需要针对iOS 7。
对于iOS 8这个问题不存在。

UPDATE: As pointed out in a comment by codyko, this is required only for iOS 7. For iOS 8 this issue does not exists.

这篇关于自动布局的UIView上约束更改不会动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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