我正在尝试使用NSAnimationContext runAnimationGroup...在Mac应用程序中对约束变化进行动画处理,但只有当我将其嵌入到dispatch_after块中时,动画才能正常工作。
结果,我得到了以下代码:
__weak typeof(self) weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf layoutSubtreeIfNeeded];
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
__strong typeof(weakSelf) strongSelf = weakSelf;
context.duration = animated ? 0.3 : 0.;
context.allowsImplicitAnimation = YES;
strongSelf.expanded = NO;
strongSelf.collapsingConstraint.priority = 900;
[strongSelf layoutSubtreeIfNeeded];
} completionHandler:^{
}];
});我做错了什么?提前感谢!
发布于 2016-03-08 22:24:57
Dispatch_after将在主队列上执行该块。如果没有它,你可能会尝试不在主线程上做动画。
如果您用dispatch_async替换dispatch_after,您还可以检查动画是否可以工作
https://stackoverflow.com/questions/35846238
复制相似问题