[英]iOS autolayout animation doesn't work on iOS 7 but works on iOS 8
[英]iOS: Autolayout doesn't work fine with animation
在我的應用程序中,我有一個情節提要,並且使用“自動布局”選項; 問題是如果我通過這種方式移動一些帶有動畫的UIImageView:
[UIView animateWithDuration:1.0 animations:^{
[image setCenter:CGPointMake(300,200)];
}];
當動畫完成圖像返回原始位置時,為什么? 如果我不檢查自動布局選項,它可以正常工作。 您能告訴我是否可以使用自動版式管理動畫嗎? 那怎么做呢?
自動布局的第一個規則! 您無法使用自動版面更改框架或視圖中心。
為了對視圖進行動畫處理,必須設置一個約束,將其用於動畫處理,然后更改該約束。
即
self.heightConstraint = [NSLayoutConstraint constraintWithItem:self.theView
attribute:
relatedBy:
toItem:
attribute:
multiplier:
constant:];
// set up the rest
[self.view addConstraint:self.heightConstraint];
然后制作動畫...
self.heightConstraint.constant = 20;
[UIView animateWithDuration:2.0
animations:^() {
[self.view layoutIfNeeded];
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.