启用Autolayout的Animate UILabel无法正常工作

时间:2014-02-21 06:49:46

标签: ios objective-c storyboard autolayout nslayoutconstraint

下面的代码是将标签的x位置移动200pts而不是动画

[UIView animateWithDuration:500.0f animations:^{
        self.myLabelContraint.constant=200 ;
        [self.view layoutIfNeeded];
    }];


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *myLabelContraint;

以上属性连接到超级视图的前导空间

故事板图片

My Storyboard

检查员面板中的Autolayout约束
    My Autolayout Constraints

1 个答案:

答案 0 :(得分:-2)

[self.view layoutIfNeeded];如果需要布局^ _ ^ 尝试在它之前添加字符串setMethod;

[UIView animateWithDuration:500.0f animations:^{
        self.myLabelContraint.constant=200; //This string can be place somewhere
        [self.view setNeedsLayout];
        [self.view layoutIfNeeded];
}];