0

I have several UIViewControllers on the application. But only on one of them willAnimateRotationToInterfaceOrientation event is calling.

How to make willAnimateRotationToInterfaceOrientation work for all visible views?

Dmitry
  • 14,306
  • 23
  • 105
  • 189
  • Did you put the shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation on every UIViewController? – jMelnik Apr 11 '13 at 20:23
  • No, I'll try it now... – Dmitry Apr 11 '13 at 20:30
  • Should we add `supportedInterfaceOrientations` and `shouldAutorotate` also? – Dmitry Apr 11 '13 at 20:34
  • These methods don't help (even they are calling). – Dmitry Apr 11 '13 at 20:39
  • ChrisF, you made a bad thing. This question has really cool answer but you marked it as duplicate and deleted the same answer on "original" question. So I think, nobody will find this answer. – Dmitry Apr 11 '13 at 21:28

1 Answers1

0

The RootViewController:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    NSDictionary *userInfo = @{
        @"toInterfaceOrientation":@(toInterfaceOrientation),
        @"duration":@(duration)};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"willAnimateRotationToInterfaceOrientation" object:nil userInfo:userInfo];
}

Other UIViewControllers:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willAnimateRotationToInterfaceOrientation:) name:@"willAnimateRotationToInterfaceOrientation" object:nil];
    }
    return self;
}

- (void)willAnimateRotationToInterfaceOrientation:(NSNotification *)notification {
    UIInterfaceOrientation toOrientation = (UIInterfaceOrientation)[notification.userInfo[@"toOrientation"] intValue];
    NSTimeInterval duration = (UIInterfaceOrientation)[notification.userInfo[@"duration"] floatValue];
    [self willAnimateRotationToInterfaceOrientation:toOrientation duration:duration];
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
    // ...
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}
Dmitry
  • 14,306
  • 23
  • 105
  • 189