【问题标题】:Animate UILabel with Autolayout turned on not working启用自动布局的动画 UILabel 不起作用
【发布时间】:2014-02-21 06:49:46
【问题描述】:

下面的代码将标签的 x 位置移动 200pts 它没有动画

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


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

above 属性连接到 superView 的前导空间

故事板图片


检查器面板中的自动布局约束

【问题讨论】:

  • @bilobatum - 前导空格:Superview - 在上图中突出显示
  • 呃,它是粗体的,但是谢谢。为什么你的动画是 500 秒?
  • @bilobatum - 只需输入更高的数字即可查看动画是否正常工作 - 降低或提高数字目前对最终输出没有影响
  • 您是否重写了任何布局方法? viewWillLayoutSubviews, viewDidLayoutSubviews, updateConstraints?

标签: ios objective-c storyboard autolayout nslayoutconstraint


【解决方案1】:

[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];
}];

【讨论】:

  • 您的代码没有为标签设置动画,它只是移动了我的问题所在的标签 - 在发布之前对其进行测试
  • 你能分享一个简单的项目例子吗?
  • MB 你需要在你的字符串中添加垃圾t@property (weak, nonatomic) IBOutlet NSLayoutConstraint *myLabelContrain
  • 我测试了我的代码。一切正常。将 animateWithDuration 更改为 0.5f
  • 我已经编辑了我的错字错误问题。在我的项目中和上面的完全一样
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多