How to get iPhones current orientation?

后端 未结 5 1543
忘掉有多难
忘掉有多难 2021-01-30 16:19

Is there a special method to get iPhones orientation? I don\'t need it in degrees or radians, I want it to return an UIInterfaceOrientation object. I just need it for an if-else

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-30 17:02

    Here is a snippet of code I hade to write because I was getting wierd issues coming back into my root view when the orientation was changed .... I you see just call out the method that should have been called but did seem to be .... this works great no errors

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    
        if ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeLeft){
            //do something or rather
            [self 
    shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft];
            NSLog(@"landscape left");
        }
        if ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeRight){
            //do something or rather
            [self 
    shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
            NSLog(@"landscape right");
        }
        if ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationPortrait){
            //do something or rather
            [self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
            NSLog(@"portrait");
        }
    }
    

提交回复
热议问题