在动画中调用layoutIfNeeded块会冻结iPhone 7上的UI
问题描述:
有没有人遇到同样的问题,在调用动画中的layoutIfNeeded时会冻结UI?在动画中调用layoutIfNeeded块会冻结iPhone 7上的UI
我有一个方法:
- (void)hide {
dispatch_block_t onMain = ^{
CGFloat height = -viewContent.frame.size.height;
[UIView animateKeyframesWithDuration:0.15f delay:0 options:0 animations:^{
[UIView addKeyframeWithRelativeStartTime:0.f relativeDuration:0.7f animations:^{
self.constraintViewContentBottom.constant = height/3;
[self layoutIfNeeded];
}];
[UIView addKeyframeWithRelativeStartTime:0.7f relativeDuration:0.3f animations:^{
self.constraintViewContentBottom.constant = height;
[self layoutIfNeeded];
}];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.2f animations:^{
self.viewBackground.alpha = 0.0f;
}
completion:^(BOOL finished) {
self.hidden = YES;
}];
}];
};
if([NSThread isMainThread]) {
onMain();
}
else {
dispatch_sync(dispatch_get_main_queue(), onMain);
}
}
其中的许多设备完美的作品,但在一个iPhone 7行:[self layoutIfNeeded];
冻结UI。
我无法调试该设备,但可以从中获取一些日志。
有谁知道我们如何解决这个问题?
感谢任何帮助。
答
设置约束条件的常量之前动画块。 layoutIfNeeded
是唯一必须加入块...
那么,基本上如果我们从[UIView animateWithDuration:0.2f动画:^ {}]调用它;方法 - 你是对的。但我已经尝试过不同的变体 - 之前,内心的结果是一样的。 =( – Andrei
你必须使用'dispatch_sync'? –
不要使用dispatch_sync! –