问题与UIView的自动布局动画 [英] Issue with UIView Auto Layout Animation

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

问题描述

我有一个的UIView 从顶部苍蝇当我打开该视图控制器。我已经将的UIView 的Y约束至-200和视图加载时,下面的叫,一切工作正常:

I have a UIView that flies from the top when I open that view controller. I've set the Y Constraint of the UIView to -200 and when the view loads, the below is called and everything works fine:

- (void)updateViewConstraints
{
    [super updateViewConstraints];
    self.popUpViewYConstraint.constant = 37.0f;
    self.closeButtonYConstraint.constant = 28.0f;
    [self.popUpBaseView setNeedsUpdateConstraints];
    [self.closeButton setNeedsUpdateConstraints];

    [UIView animateWithDuration:0.25f animations:^{
        [self.popUpBaseView layoutIfNeeded];
        [self.closeButton layoutIfNeeded];
        [self.view layoutIfNeeded];
    }];
}

但现在我有一个关闭按钮应该动画的UIView 回-200的位置,然后从屏幕视图控制器。但热闹是不是正在发生。视图控制器是越来越直接删除。下面是我在做什么:

But now I have a close button that should animate the UIView back to the -200 position and then remove the view controller from the screen. But this animation is not taking place. The view controller is getting removed directly. Here's what I'm doing:

- (IBAction)closePressed:(id)sender
{
    NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
    self.navigationController.viewControllers = navigationArray;

    [UIView animateWithDuration:2.0f animations:^{
        self.popUpViewYConstraint.constant = -200.0f;
        [self.popUpBaseView layoutIfNeeded];
    } completion:^(BOOL finished){
        [navigationArray removeObjectAtIndex: 1];
        [self.baseView removeFromSuperview];
        [self.view removeFromSuperview];
    }];
}

我提到<一个href=\"http://stackoverflow.com/questions/21014087/uiview-animated-changes-with-auto-layout-constraints\">this链接。这似乎是为他们工作,但对我不起作用。
请帮助。

I referred to this link. It seems to be working for them but doesn't work for me. Please help.

推荐答案

这个怎么样

- (IBAction)closePressed:(id)sender
{
    NSMutableArray *navigationArray = [[NSMutableArray alloc]:initWithArray:self.navigationController.viewControllers];
    self.navigationController.viewControllers = navigationArray;

    // I am sure the constant should be set outside the animation block. It won't happen until next run loop, which will be inside the block. 
    self.popUpViewYConstraint.constant = -200.0f;
    // setNeedsUpdateConstraints should be called on the view to which the constraint is added, not the view affected by the constraint.
    [self.baseView setNeedsUpdateConstraints];

    [UIView animateWithDuration:2.0f animations:^{
         // I think this should be topmost view
         [self.view layoutIfNeeded];
    } completion:^(BOOL finished){
        [navigationArray removeObjectAtIndex: 1];
        [self.baseView removeFromSuperview];
        [self.view removeFromSuperview];
    }];
 }

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

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