iOS monitor horizontal screen and vertical screen hide status bar

Time:2022-8-4
BOOL _isFullScreen;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotated:) name:UIDeviceOrientationDidChangeNotification object:nil];

- (void)rotated:(NSNotification *)notification
{
    UIDevice *dv = notification.object;
    /*
     
     UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight
     */
    if (dv.orientation == UIDeviceOrientationLandscapeLeft ||
        dv.orientation == UIDeviceOrientationLandscapeRight)
    {
        NSLog(@"horizontal screen");
        _isFullScreen = true;
  
    }else if (dv.orientation == UIDeviceOrientationFaceUp ||
         dv.orientation == UIDeviceOrientationFaceDown)
     {
         NSLog(@"face");
     }else{
         NSLog(@"Portrait");
         _isFullScreen = NO;
    }
    [self reloadStatuestBar];
}
- (BOOL)prefersStatusBarHidden
{
    return _isFullScreen;
}
- (void)reloadStatuestBar {
    if ( [self  respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)] ) {
        // go prefersStatusBarHidden
         [self setNeedsStatusBarAppearanceUpdate];
    } else {
        [[UIApplication sharedApplication] setStatusBarHidden:_isFullScreen];
    }
}

Recommended Today

Ansible combat MySQL installation

Do the preparatory work first, prepare a client, and then equip a master machine. Check connectivity: [[email protected] ~]# ansible mytest -m ping 10.128.25.175| SUCCESS => { “ansible_facts”: { “discovered_interpreter_python”: “/usr/bin/python” }, “changed”: false, “ping”: “pong” } [[email protected] ~]# 1. Ansible module search method 1. Ansible’s yum module search yum module online documentation: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html Example: – […]