Shu*_*puS 1 objective-c screen-rotation ios appdelegate
我有一个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;
}
Run Code Online (Sandbox Code Playgroud)
您可以注册Notification如下:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDidChangeStatusBarOrientationNotification:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
Run Code Online (Sandbox Code Playgroud)
然后,实现它AppDelegate:
- (void)handleDidChangeStatusBarOrientationNotification:(NSNotification *)notification;
{
NSLog(@"The orientation changed to %@", [notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey]);
}
Run Code Online (Sandbox Code Playgroud)
请享用.:)
| 归档时间: |
|
| 查看次数: |
752 次 |
| 最近记录: |