如果屏幕方向已更改,AppDelegate应调用该方法

 孝敏敏__216 发布于 2023-02-12 18:22

我有一个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]);
}

请享用.:)

1 个回答
  • 您可以注册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]);
    }
    

    请享用.:)

    2023-02-12 18:23 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有