我有一个popover
,我在TabBarItem
中提到了这就是为什么我在AppDelegate
中提出这个问题,但是我需要在新的位置重新显示popover
方向已经改变。在我的应用的其他地方,我只使用didRotateFromInterfaceOrientation
方法,但它没有在AppDelegate
中调用。我该如何解决这个问题?
我通过以下代码提出了一个popover:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (viewController == [self.objTabBarController.viewControllers objectAtIndex:2])
{
if (self.settingsPopover == nil) {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main - iPad" bundle: nil];
SettingsViewController *settingsController = [mainStoryboard instantiateViewControllerWithIdentifier: @"SettingsPopover"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:settingsController];
self.settingsPopover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
CGSize tabBarSize = self.objTabBarController.tabBar.frame.size;
CGPoint center = [self.window.rootViewController.view convertPoint:self.objTabBarController.tabBar.center fromView:self.objTabBarController.tabBar.superview];
center.x += 105;
center.y -= tabBarSize.height / 2;
CGRect rect = {center, CGSizeZero};
[self.settingsPopover presentPopoverFromRect:rect inView:self.window.rootViewController.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
} else {
[self.settingsPopover dismissPopoverAnimated:NO];
self.settingsPopover = nil;
}
return NO;
}
}
return YES;
}
答案 0 :(得分:5)
您可以注册Notification
,如下所示:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDidChangeStatusBarOrientationNotification:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
然后,在AppDelegate
:
- (void)handleDidChangeStatusBarOrientationNotification:(NSNotification *)notification;
{
NSLog(@"The orientation changed to %@", [notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey]);
}
享受。 :)