【发布时间】:2017-08-31 08:09:37
【问题描述】:
有没有人遇到过同样的问题,在动画块中调用 layoutIfNeeded 会冻结 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。
我无法调试该设备,但可以从中获取一些日志。
有谁知道我们如何解决这个问题?
感谢任何帮助。
【问题讨论】:
标签: ios objective-c uiview nslayoutconstraint