ios - animatewithduration在iOS 8中不起作用

标签 ios ios7 ios8 uiviewanimation

我正在使用以下代码来设置带有动画的三个标签的帧。它在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];
}];

关于ios - animatewithduration在iOS 8中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26865794/

相关文章:

ios - swift:将字符串转换为 double 问题

objective-c - UIGravityBehavior 不工作

swift - 带有 NsurlConnection 的 UIViewActivityIndi​​cator 不会快速停止动画

ios - 如何可靠地确定 Passbook 是否可用?

swift - 如何在 Swift 中将变量实例化为对象?

ios - 什么是 UILocalNotification 重复日历用于以及如何使用

ios - 如何在 iPhone 6 上安装旧版本的 TestFlight

ios - 检测仅添加照片权限

ios - IOS 7中UINavigationBar下的白线

ios - iOS 7中的Round Rect UIBarButton