我有一个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; }
Vinay Jain.. 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]); }
请享用.:)
您可以注册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]); }
请享用.:)