繁体   English   中英

animatewithduration在iOS 8中不起作用

[英]animatewithduration is not working in ios 8

我正在使用以下代码来设置带有动画的三个标签的帧。 它在ios 7中可以正常工作,但在ios 8中似乎没有动画。

请帮助我解决这种情况。

int total = avgAwake+avgLight+avgSound;
[UIView animateWithDuration:1.0 animations:^{

    CGRect newFrame = lblSound.frame;
    newFrame.size.width = (avgSound*250)/total;
    lblSound.frame   = newFrame;

    newFrame.size.width += (avgLight*250)/total;
    lblLight.frame   = newFrame;

    newFrame.size.width += (avgAwake*250)/total;
    lblAwake.frame   = newFrame;

}];

我遇到了一个非常类似的问题,因此我改用了自动布局。

对于此解决方案,您必须定义新的约束,然后强制更新约束。 动画会更改布局:

//define the new constrains for "theView" here
.....

[theView setNeedsUpdateConstraints];
[UIView animateWithDuration:1.0f animations:^{
    [theView layoutIfNeeded];
}];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM