iPhone + CGAffineTransFormRotate(pi/2) + statusBarHidden:YES + presentModalViewController = 20 pixels of white space

前端 未结 3 1299
深忆病人
深忆病人 2021-01-01 07:33

I think the title is pretty descriptive:

I perform all 3 of these operations on a view, the result is 20 pixels of white space along the left side of the screen (if

相关标签:
3条回答
  • 2021-01-01 07:50

    Ok, I figured it out. As usual it was the result of more than 1 issue. These problems all occur before I even push the modal view:

    First, In my code I was resizing my view like so:

    [self.view setFrame: [[UIScreen mainScreen] applicationFrame]];
    

    After you hide the status bar, applicationFrame STILL returns a 320x460 rect (not 320x480). Not sure why, but the following fixes it:

    [self.view setFrame: [[UIScreen mainScreen] bounds]];
    

    This gets the whole screen which I lifted from:

    Fullscreen UIView with Status bar and Navigation Bar overlay on the top

    Second, and in the same line of code, I am not talking to the correct viewController. Since I am in a Navigation Based app, I must talk to the NavigationController. If not, the Navigation Bar never gets the message to move to the top of the screen to cover the space left by the status bar (which resulted in my white space). So one more correction to this line of code:

      [[self.navigationController view] setFrame: [[UIScreen mainScreen] bounds]];
    

    Lastly, after all of this, I can push my modal view with confidence.

    0 讨论(0)
  • 2021-01-01 07:55

    None of those work for me. What DID work was the following: I declared a (global) variable in my ViewController.h file

    CGRect                  contentRect;
    

    and in my ViewController.m at my viewDidLoad method I initialize it like this:

    contentRect = self.view.frame;
    

    then, to dismiss the picker, I use

      [self dismissModalViewControllerAnimated:YES]; // Or any other command 
      [self.view setFrame:contentRect]; // ta-da! all set back to normal.
    
    0 讨论(0)
  • 2021-01-01 08:05

    I think you may need to recenter your center:

    // Set the center point of the view to the center point of the window's content area.      
    self.view.center = CGPointMake(160.0, 240.0);
    

    This is the whole init method I use for landscape views and works without an issue. Just make sure to set your nib to the right size too.

    // Implement viewDidLoad to do additional setup after loading the view.
    - (void)viewDidLoad {
      [super viewDidLoad];
    
      // Rotate to landscape
      self.view.frame = CGRectMake(0, 0, 480.0, 320.0);
      if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
        CGAffineTransform transform = self.view.transform;
    
        // Set the center point of the view to the center point of the window's content area.      
        self.view.center = CGPointMake(160.0, 240.0);
    
        // Rotate the view 90 degrees around its new center point.
        transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
        self.view.transform = transform;
      }
    }
    
    0 讨论(0)
提交回复
热议问题