2014-12-30 90 views
1

我試圖使用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上的任何建議?

回答

4

如果用[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