0
我試圖在使用的Mac應用程序中動畫約束更改,但動畫只有在嵌入dispatch_after
塊內時才能正常工作。使用NSAnimationContext動畫自動佈局僅適用於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:^{
}];
});
我在做什麼錯? 在此先感謝!
我已經檢查了很多次。它在主線上。 'dispatch_async(dispatch_get_main_queue(),^ {' - no animation ... – Bambuh
你能分享一下你的代碼嗎? –