0

I'm trying to animate constraints change in Mac app using NSAnimationContext runAnimationGroup... but animation works fine only if I embed it inside dispatch_after block.

In result I have this code:

__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:^{
    }];
});

What am I doing wrong? Thanks in advance!

Bambuh
  • 11
  • 1
  • 3

1 Answers1

0

Dispatch_after will execute the block on the main queue. Possibly, without it you tried to do animation not on the main thread.

Also you can check if animation will work if you replace dispatch_after with dispatch_async

  • I've already checked this many times. It's on main thread. `dispatch_async(dispatch_get_main_queue(), ^{` - no animation... – Bambuh Mar 09 '16 at 16:11