【问题标题】:How to solve the view broken when the personal hotspot is on in ios?如何解决ios中个人热点开启时视图中断的问题?
【发布时间】:2017-05-11 08:37:30
【问题描述】:

我以编程方式为UITabBarController 创建视图。

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;
    }

个人热点关闭时可以正常使用。

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

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

【问题讨论】:

    标签: ios objective-c view uitabbarcontroller personal-hotspot


    【解决方案1】:

    检查一下

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

     [[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;
        }];
    }
    

    【讨论】:

    • 我试过了,但没有收到任何通知。
    • 它对我来说很好......你用断点检查了什么
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 2019-08-18
    • 1970-01-01
    • 2019-10-31
    相关资源
    最近更新 更多