自动布局约束变化UIView不动画iOS 7

问题描述:

我试图使用AutoLayout从“自下而上”动画视图。自动布局约束变化UIView不动画iOS 7

这在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上的任何建议?

如果用[self.aVC.view layoutIfNeeded]更换[self.view layoutIfNeeded],这将在两个的iOS版本。我不知道具体原因。

编辑。

请尝试这样的事情。

[self.aVC.view layoutIfNeeded]; 
[UIView animateWithDuration:2 animations:^{ 
    constraint.constant = -25; 
    [self.view layoutIfNeeded]; 
}]; 
+0

请参阅我更新的问题;它不适用于具有子视图的xib。 – kernix

+0

我下载旧的,它为我工作。你有没有修改xib中的任何东西? – gabbler

+0

是的,它确实在第一次提交时使用了一个空的xib。我已经为xib添加了一个标签和两个图像,现在它不会在iOS 7上生成动画。谢谢。 – kernix