Get current orientation of iPad?

后端 未结 11 1742
野趣味
野趣味 2020-12-02 07:28

In a given event handler (not the \"shouldAutorotateToInterfaceOrientation\" method) how do I detect the current iPad orientation? I have a text field I have to animate up

11条回答
  •  猫巷女王i
    2020-12-02 08:07

    I found a trick to solve the FaceUp orientation issue!!!

    Delay the orientation check till AFTER the app has started running, then set variables, view sizes, etc.!!!

    //CODE
    
    - (void)viewDidLoad {
    
      [super viewDidLoad];
    
      //DELAY
      [NSTimer scheduledTimerWithTimeInterval:0.5 
                         target:self 
                         selector:@selector(delayedCheck) 
                         userInfo:nil 
                         repeats:NO];
    
    }
    
    
    -(void)delayedCheck{
    
      //DETERMINE ORIENTATION
      if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait ){
          FACING = @"PU";
      }
      if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown ){
          FACING = @"PD";
      }
      if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
          FACING = @"LL";
      }
      if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight ){
          FACING = @"LR";
      } 
      //DETERMINE ORIENTATION
    
      //START
      [self setStuff];
      //START
    
    }
    
    
    -(void)setStuff{
    
      if( FACING == @"PU" ){
              //logic for Portrait
      }
      else
      if( FACING == @"PD" ){
              //logic for PortraitUpsideDown
      }
      else{ 
      if( FACING == @"LL"){
              //logic for LandscapeLeft
      }
      else
      if( FACING == @"LR" ){
              //logic for LandscapeRight
      }
    
    }
    
    //CODE
    

    You can addSubviews, position elements, etc. in the 'setStuff' function ... anything that would initially depend on the orientation!!!

    :D

    -Chris Allinson

提交回复
热议问题