Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewWillTransitionToSize coordinator ignores block

Tried gaming the new rotation methods, I need to know if the device is being rotated in order to defer and cancel an action that is not required in the event of rotation.

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

    _rotating = YES;

    [coordinator notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        _rotating = NO;
    }];
}

Seems straight forward and should work based on my interpretation of the documentation but apparently no. It seems that _rotating is set to YES and never gets set back to NO. Consequently, it seems my completion block is never called.

like image 732
Dean Davids Avatar asked Jan 10 '23 13:01

Dean Davids


1 Answers

I had the same problem. I dived into the docs. The block you specify in notifyWhenInteractionEndsUsingBlock gets called when:

When a transition changes from interactive to non-interactive then handler is invoked.

However, rotation is not an interactive transition. Once it starts you cannot interact with it. That's why the handler is never called.

I ended up using animateAlongsideTransition:completion: method. It works like a charm.

- (void)viewWillTransitionToSize:(CGSize)size
       withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
{
    _rotating = YES;

    [super viewWillTransitionToSize:size
          withTransitionCoordinator:coordinator];

    [coordinator animateAlongsideTransition:nil
                                 completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
     {
        _rotating = NO;
     }];
}
like image 84
Rafa de King Avatar answered Jan 17 '23 15:01

Rafa de King