How can I know the orientation changed in AppDelegate

后端 未结 2 1233
说谎
说谎 2021-01-20 14:34

The function of how the device know the changement of orientation is -(void)viewWillLayoutSubviews and -(void)viewDidLayoutSubviews But, they are just in the controllers;

相关标签:
2条回答
  • 2021-01-20 14:48

    You can register for notifications when rotation occurs

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(handleDidChangeStatusBarOrientationNotification:) 
                                                 name:UIApplicationDidChangeStatusBarOrientationNotification 
                                               object:nil];
    

    Then implement the method that gets called when the message is sent

    - (void)handleDidChangeStatusBarOrientationNotification:(NSNotification *)notification;
    {
      // Do something interesting
      NSLog(@"The orientation is %@", [notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey]);
    }
    

    Alternatively check out the docs for UIApplicationDidChangeStatusBarOrientationNotification which will provide you with the

    0 讨论(0)
  • 2021-01-20 15:02

    If you are talking about the interface orientation you could observe theUIApplicationDidChangeStatusBarOrientationNotification and if you want to be notified when the device orientation changed you can observe UIDeviceOrientationDidChangeNotification

    0 讨论(0)
提交回复
热议问题