0

enter image description here

Consider the screen shot above. The UIView is positioned too much to the top causing the upper test string to be partially off and there is a gap shown at the bottom screen. The screen shot also shows its corresponding positioning values in IB : x = 0 and y = 20. So there is actually an offset (y = 20) default to clear the top status bar. But still the status bar shown covers part of the UIView.

The x, y entry is greyed out, so it seems not possible to change its values. Have spent quite some time but still not able to solve this seemingly easy problem. Hope that somebody who is familiar with this could give some hints on how this should be done.

Update :

Have done it in code as suggested. It seems to work ok. If you find any errors please let me know ...

- (void)viewDidLoad
{
CGRect  position_and_size;
CGPoint cg_point;
CGSize  cg_size;

[super viewDidLoad];

// setup after loading the view from its nib.

NSLog(@" --- Screen loaded --- ");

cg_size.width  = 320;
cg_size.height = 460;

cg_point.x =  0;
cg_point.y = 20;

position_and_size.origin = cg_point;
position_and_size.size   = cg_size;


[[self view] setFrame : position_and_size];

}

.

The following is the latest screen shot :

screen shot

Stanley
  • 4,446
  • 7
  • 30
  • 48
  • 1
    Try to play with Autoresizing mask. Or in viewDidLoad method (within your view controller) adjust the view frame to start with an offset of 20 for y position. – Lorenzo B Nov 24 '11 at 13:47
  • possible duplicate of [Weird statusbar offset in iPhone app](http://stackoverflow.com/questions/6705926/weird-statusbar-offset-in-iphone-app) – Caleb Nov 24 '11 at 13:53
  • Not sure if this is the Autoresize mask. But I changed the "Simulated Metrics" Size from none to "iPhone/iPod touch Full Screen" and the offset remains the same. – Stanley Nov 24 '11 at 13:59
  • You want to calculate position_and_size by yourself every time your view moves off screen? Use `view.bounds` property of parent view instead. – Evgeny Aleksandrov Nov 28 '11 at 09:38
  • @Condor, thanks for the comment. But from documentation, bounds is a property. So we need to specify it at least once. Please correct me if I am wrong. – Stanley Nov 29 '11 at 01:13
  • @Stanley, no, you don't need to do something with this property before using it. See accepted answer in [this](http://stackoverflow.com/questions/519689/) question for example. – Evgeny Aleksandrov Nov 29 '11 at 11:25
  • The "this" link is very helpful, thanks ... – Stanley Nov 29 '11 at 20:46

2 Answers2

1

You can fix it programmatically:

[yourSubView setFrame:self.view.bounds];

Assuming self.view - parent view, where it should fit.

Evgeny Aleksandrov
  • 780
  • 14
  • 32
1

The problem is that you're placing a view that's 460 pixels high at {0,0} in a window that's 480 pixels high. The first 20 pixels of your view therefore ends up under the status bar, and the view fails to cover the bottom 20 pixels of the window. You can fix it in any of the following ways:

  • Change the autoresize options so that the view's size will be automatically adjusted to fill the window.

  • Resize the view to match the window's bound, either in code or in IB.

  • Position the view at {0,20}, either in code or in IB.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • Thanks for the detailed answer. Will try what you suggested and the possible duplicate link is also helpful. Also about the {0, 20} entry, I think it is set as a default already as shown on the upper left of the screen shot. – Stanley Nov 24 '11 at 14:29
  • Have tried the autoresize options just now, but could not get it to work. Guess it should be able to be done in code as you suggested. Thanks ... :) – Stanley Nov 24 '11 at 14:37
  • You might want to post the code you're using to add the view, if you're doing that programmatically. – Caleb Nov 24 '11 at 15:29
  • The coding is posted, seems to work ok. If you find any errors please let me know. – Stanley Nov 25 '11 at 19:51