ios - 如何解决ios中个人热点开启时 View 中断的问题?

标签 ios objective-c view uitabbarcontroller personal-hotspot

我以编程方式为 UITabBarController 创建 View .

ViewController.m

    @interface ViewController ()
    {   
        UITabBarController *tabBarController;
        MainViewController *mainView;
        GroupViewController *grpView;
    }

    -(id)init
    {
        self=[super init];

        [self initControl];
        return self;
    }


    -(void)initControl
    {

    }

    - (void)viewDidLoad {
        [super viewDidLoad];

        NSLog(@"ViewController - viewDidLoad");
        self.mainView=[[MainViewController alloc] init];
        self.grpView=[[GroupViewController alloc] initWithNibName:@"GroupViewController" bundle:[NSBundle mainBundle]];
        self.meView=[[MeViewController alloc] initWithNibName:@"MeViewController" bundle:[NSBundle mainBundle]];



        UITabBarItem *tempItem=[[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Device", @"Device") image:[[UIImage imageNamed:@"device1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:1];
        tempItem.selectedImage=[UIImage imageNamed:@"device"];
        mainView.tabBarItem=tempItem;
        tempItem.imageInsets = UIEdgeInsetsMake(0.0, 0, -0.0, 0);


        tempItem=[[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Group", @"Group") image:[[UIImage imageNamed:@"group1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:2];
        tempItem.selectedImage=[UIImage imageNamed:@"group1"];
        grpView.tabBarItem=tempItem;
        tempItem.imageInsets = UIEdgeInsetsMake(0.0, 0, -0.0, 0);

        self.tabBarController= [[UITabBarController alloc] init];
        NSMutableArray *controllers=[[NSMutableArray alloc] initWithCapacity:2];

        [controllers addObject:self.mainView];
        [controllers addObject:self.grpView];

        self.tabBarController.viewControllers =controllers;
        [self.view addSubview:self.tabBarController.view];
        self.tabBarController.delegate=self;
    }

当个人热点关闭时,它工作正常。

enter image description here

当我打开热点并且有人连接到 iPhone 时,然后打开应用程序。 view像下面的屏幕截图 当个人热点开启 .

enter image description here

个人热点开启时如何解决?
提前致谢。

最佳答案

检查这个

为状态栏添加观察者改变了长度:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(StatusbarspaceHide:) name:UIApplicationWillEnterForegroundNotification object:nil];

状态栏更改时的操作:
-(void)StatusbarspaceHide:(NSNotificationCenter *)notification{
    [UIView animateWithDuration:0.35 animations:^{
        // CGRect windowFrame = ((UINavigationController *)((UITabBarController *)self.window.rootViewController).viewControllers[0]).view.frame;
        CGRect windowFrame = self.view.frame;

        if (self.view.frame.origin.y > 20) {
            windowFrame.origin.y = self.view.frame.size.height - 20 ;// old status bar frame is 20
        }
        self.view.frame = windowFrame;
    }];
}

关于ios - 如何解决ios中个人热点开启时 View 中断的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43910465/

相关文章:

ios - 以编程方式创建时不显示导航 Controller

ios - 通过 App Delegate 从 UINavigationController 呈现 UIViewController

ios - 如何解析响应标记内包含 XML 文档的 SOAP 响应

ios - 来自终止状态的可操作通知

ios - 不使用 UIImage 上传 GIF

iOS - 父/ subview 的 quartz 绘图问题

asp.net-mvc - 未找到 View 'Home' 或其主视图,或者没有 View 引擎支持搜索的位置。搜索了以下位置 : 'sporadic error'

Android 自定义 View 忽略 XML 中的 `android:enabled`?

objective-c - NSManagedObjectContext : exception breakpoint stops at save: method, 但没有日志/崩溃/错误

Android 将 View 添加到锁定屏幕