I created a View Based App with Apple's templates. I added the code to the viewDidLoad method:
NSLog(@"origin (x, y): (%f, %f)", self.view.frame.origin.x, self.view.frame.origin.y);
NSLog(@"frame (w, h): (%f, %f)", self.view.frame.size.width, self.view.frame.size.height);
My output is:
2011-06-05 12:开发者_StackOverflow12:02.907 ViewBasedApp[1753:207] origin (x, y): (0.000000, 20.000000)
2011-06-05 12:12:02.908 ViewBasedApp[1753:207] frame (w, h): (320.000000, 460.000000)
Why does XCode put the origin at (0, 20) instead of (0,0)? I did not change any other default settings.
The reason I ask is when I use the Window Based App and add in my own subclass of UIViewController and add it programmatically by doing:
SomeViewController *vc = [[SomeViewController alloc] initWithNibName:@"HomeView" bundle:nil];
self.homeViewController = vc;
[self.window addSubview:homeViewController.view];
[vc release];
my output is:
2011-06-05 12:14:47.405 WhereAmIiPhone[1780:207] origin (x, y): (0.000000, 0.000000)
2011-06-05 12:14:47.405 WhereAmIiPhone[1780:207] frame (w, h): (320.000000, 460.000000)
I was wondering why the difference in 20 points for the origin and what I can do to avoid having my view being thrown off by 20 points. Thanks.
I believe it is due to the status bar that is 20px height.
that normal and you don't have to worry about this, just make sure your view are 460 points height.
Any way if you want to hide the status bar you can add:
Status bar is initially hidden NO
to your info.plist
But be aware that apple asks you to have agood reson for that.
EDIT
to lower your view in 20 points try:
mapview.frame = CGRectOffset(mapView.frame,0,20).
精彩评论