Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
animatewithduration在ios 8中不起作用_Ios_Ios7_Ios8_Uiviewanimation - Fatal编程技术网

animatewithduration在ios 8中不起作用

animatewithduration在ios 8中不起作用,ios,ios7,ios8,uiviewanimation,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

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

我想这与自动布局有关。最简单的方法是切换到基于约束的动画。请确保为标签创建宽度约束,并更改其常量,而不是使用边框。尝试使用
NSInteger total=..
float total
而不是
int total
@TimBodeit我也使用了autolayout,但它在ios 8中仍然不起作用。使用约束并调用layoutIfNeeded应该可以完成这项工作那里