ios - AnimateWithDuration 无法按预期工作
<p><p>我正在尝试运行一个示例来测试此功能。我在 Storyboard中有一个标签和一个按钮,并且我在 ViewController 中引用了标签的底部约束。当我使用按钮时,我希望标签与动画一起移动,但它在没有它的情况下移动。这是按钮的代码:</p>
<pre><code>- (IBAction)sd:(id)sender {
[UIView animateWithDuration:0.5f animations:^{
self.constraint.constant += 50;
}];
}
</code></pre>
<p>我知道如何快速使用它,但我在 objective-c中遇到问题,我知道这只是一个小错误......有什么帮助吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这不是为受 Autolayout 约束的 UI 组件设置动画的正确方法。您应该首先更新约束,然后调用 <a href="https://developer.apple.com/reference/uikit/uiview/1622507-layoutifneeded?language=objc" rel="noreferrer noopener nofollow"><code>layoutIfNeeded</code></a>在动画 block 内:</p>
<pre><code>self.constraint.constant += 50;
[UIView animateWithDuration:0.5f animations:^{
;
}];
</code></pre></p>
<p style="font-size: 20px;">关于ios - AnimateWithDuration 无法按预期工作,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/43938237/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/43938237/
</a>
</p>
页:
[1]