animatewithduration在ios 8中不起作用
我使用下面的代码来设置动画中三个标签的帧。它在ios 7中运行得非常完美,但在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
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应该可以完成这项工作那里