UI Elements placed in IB appears shifted up in Sim

2019-08-12 14:23发布

问题:

I dont know if I am missing something here but when I drop elements (UIImage or UILabel) in IB and run the app in simulator, the UI elements are shifting up a little (Snapping to status bar if I place them at first blue HIG line).

Looks like some setting I am overlooking. Does this sound familiar? please help!

Added Screenshot to explain whats going on ...

  1. In Interface Builder

alt text http://dl.dropbox.com/u/3093402/Images/IB.png

  1. In Simulator

alt text http://dl.dropbox.com/u/3093402/Images/Simulator.png

回答1:

Try this: select the view in Interface Builder and then in the Inspector, under “Simulated User Interface Elements,” change the status bar to “Gray.”



回答2:

Ok ... heres whats happening in detail - http://discussions.apple.com/message.jspa?messageID=10861335

And heres what I did to resolve this - In the view controller code

- (void)viewDidLoad {
     CGRect newFrame = self.view.frame;
     newFrame.origin.y += 20;
     self.view.frame = newFrame;
    [super viewDidLoad];
}

Just move the frame of the newly added view (first view to the window) 20 pixels down and everything should fit nicely. This some how fixes view position for following views also. Dont know how?

Then you will see the UI elements exactly in the same position in Simulator and Device as you see in IB.

Hope this helps :)

Dev.