约束更改的自动布局UIView不会为iOS 7设置动画

时间:2014-12-30 11:05:32

标签: ios iphone ios7 ios8 autolayout

我试图动画来自"自下而上的视图"使用AutoLayout。

这在iOS 8中效果很好,但是它在iOS 7中没有动画效果。

以下是代码段:

@interface ViewController ()
@property (strong) AViewController *aVC;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.aVC = [[AViewController alloc] init];
    self.aVC.view.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:self.aVC.view];
    [self.aVC.view autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [self.aVC.view autoSetDimension:ALDimensionHeight    toSize:100];
    [self.aVC.view autoSetDimension:ALDimensionWidth     toSize:320];
     NSLayoutConstraint *constraint = [self.aVC.view autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:-100];
     [self.view layoutIfNeeded];
    [UIView animateWithDuration:2 animations:^{
        constraint.constant = -25;
        [self.view layoutIfNeeded];
    }];

}

我使用了很棒的PureLayout类别,轻松添加约束。

附加project sample on Github - 适用于iOS 8模拟器,而不适用于iOS 7模拟器。

有关如何在iOS 7上运行的任何建议吗?

1 个答案:

答案 0 :(得分:4)

如果您将[self.view layoutIfNeeded]替换为[self.aVC.view layoutIfNeeded],则可以在两个iOS版本上使用。我不知道具体原因。

编辑。

请尝试这样的事情。

[self.aVC.view layoutIfNeeded];
[UIView animateWithDuration:2 animations:^{
    constraint.constant = -25;
    [self.view layoutIfNeeded];
}];
相关问题