0

I am getting a black patch partially on screen. Its a UIView and this happens only when device is in landscape mode. In portrait, it works fine.

Actual screenshot on iPad 2: (Check the black patch) enter image description here

Here is my View Hierarchy in Xcode: (Please check the UIView highlighted. It is the one which is not completely stretched to the device's width) enter image description here

Being newbie in iOS development, I am not sure about where is it going wrong. Would this be because of wrong dimensions of self.view ?

This is how I am defining self.view

CGRect deviceDimensions = [[UIScreen mainScreen] applicationFrame];
self.view = [[UIView alloc] initWithFrame:deviceDimensions];

I tried explicitly setting width (just for debugging) as follows:

CGRect deviceDimensions = [[UIScreen mainScreen] applicationFrame];
deviceDimensions.size.width = 768;
self.view = [[UIView alloc] initWithFrame:deviceDimensions];

but still its showing same.

Device: iPad 2 - Screen size: 1024x768 iOS 8.2 Xcode v6.2

Thanks.

Kapil Jituri
  • 1,241
  • 14
  • 25

1 Answers1

0

Auto-Layout. It's a beast of a tool but it takes a couple of minutes to get the basics down. Select the view in IB, and add height and width constraints to your view, like so: enter image description here

If you prefer code, Take a look at the autoresizingMask property:

-(BOOL)shouldAutorotate
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (orientation != UIInterfaceLandscape) {
[view.superview setAutoresizesSubviews:YES];
    return YES;
   }
}
Henry F
  • 4,960
  • 11
  • 55
  • 98