iOS: Device orientation on load

前端 未结 16 1919
遥遥无期
遥遥无期 2020-11-28 23:45

It seems that when my app loads, it does not know its current orientation:

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (o         


        
16条回答
  •  爱一瞬间的悲伤
    2020-11-29 00:12

    Try this one. it's work for me. gnarly at that time of didfinishedlaunch method not detect device orientation. its take by default as a portrait. so. i am using to check stats bar orientation . i test this code. put it in didfinishedlaunch method in appdeleget.

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

    if(orientation == 0) {//Default orientation
        //UI is in Default (Portrait) -- this is really a just a failsafe.
    
        NSLog("for portrait");
    
    
    }else if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
    {
    
        NSLog("portrait");
    }else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
    
        NSLog("Landscap");
    }
    

提交回复
热议问题