ABPeoplePickerNavigationController - iphone

This is probably a really basic question, but when I make my ABPeoplePickerNavigationController instance (addBookViewer)visible by running,
[self presentModalViewController:addBookViewer animated:YES]
the contact view pops up, but is cut off by the top most bar of the display (the bar showing the AT&T signal strength, clock and battery charge). Is there a way to programatically change the addBookViewer so that it is not cut off by the static status bar?
Thanks,
Dave

It looks like ABPeoplePickerNavigationController inherits from UIViewController. Perhaps you could try editing the view's frame before presenting it:
addBookViewer.view.frame = CGRectMake(0, 20, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height - 20);

I suspect it is because the view controller that you are calling presentModalViewController:animated: on has a frame that is also being covered, but you don't notice, probably have plenty of head room, make sure you have the status bar in your nib file so that it is laid out correctly.

Related

Troubles with iPhone UINavigationController (UINavigationBar in wrong place)

I'm in the process of making some adjustments to an app, including changing to a navigation-based interface. As part of that change I've written a view controller that contains a UINavigationController. The problem is, for some strange reason the UINavigationBar and UIToolbar managed by the UINavigationController are displaced 20px down from where they should be. I've managed to produce the following example that demonstrates the issue:
// MyAppDelegate.m
#implementation MyAppDelegate
#synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.frame = [[UIScreen mainScreen] applicationFrame];
[self.window makeKeyAndVisible];
TestController* tc = [TestController new];
[self.window addSubview:tc.view];
return YES;
}
#end
// TestController.m
#implementation TestController
- (void)loadView
{
self.view = [[UIView alloc] initWithFrame:CGRectZero];
UINavigationController* navController = [UINavigationController new];
navController.view.backgroundColor = [UIColor blueColor];
[navController setToolbarHidden:NO animated:NO];
[self.view addSubview:navController.view];
}
#end
This produces the following result on my machine:
As you can see, the controls are 20px down from where I'd expect them to be. I've tried just about everything I can think of (various combinations of wantsFullScreenLayout, autoresizesSubviews, etc) with no positive effect. This also has nothing to do with programatically messing with the statusbar (as seems to be the case in most other examples of this I have come across), since I do not at any point mess with the statusbar. This occurs with or without a root view controller in the navigation controller - if there is one, it's contents are shifted 20px down too (so they actually are in the right place relative to the navigation bar and toolbar).
Any help much appreciated!
EDIT: After a bit of investigation, it seems that removing the line self.window.frame = [[UIScreen mainScreen] applicationFrame]; seems to correct the positioning of the navigation bar and toolbar and content. That said, now some other views in the application are in the wrong place (up underneath the statusbar). My understanding is that line is generally recommended to ensure that the window is the correct size?
As mentioned in my edit, removing the line self.window.frame = [[UIScreen mainScreen] applicationFrame]; seems to have corrected 95% of my problems. I've managed to fudge an approach to fix the other 5% by using the same background colour for my window and the remaining views having issues, but I can't say I'm thrilled with this solution - I shouldn't have to do that.
I'll keep experimenting, and if I find a better result will certainly post an edit here.
UINavigationController does not play nicely with being used as a subview; as you've noticed, it will often leave room for the status bar even when it is not actually under the status bar. If you're not trying to write your own container view controller, you should rework your code to not be adding a view controller's view as a subview at all.
That said, I've had luck fixing it by setting wantsFullScreenLayout to NO on the UINavigationController, which will make it not leave space for the status bar. You would, of course, want to do this just after allocating it, before loadView gets triggered.

frequent bug in UI (tabbar pushed from navigation)

I have encountered this bug several times. I have a application with a navigation controller (navbar hidden). when a button is "pressed" i want to push another view with a tabbarviewcontroller. When the new view is pushed, it's 20 pixels lower than it should (and part of the tabbar is not visible).
If I enter modal-view controller from the tabbarviewcontroller and then i dismiss it, the tabbarviewcontroller is shown properly.
I put the status bar in every view to be unspecified (thought that was the problem) and i un-checked the autoresize subviews from each view.
in your code use bounds property instead of application frame . in my it worked hope to work in case too.......:)
This sounds like it might be related to a known NIB/XIB file bug (for more information see: http://forums.bignerdranch.com/viewtopic.php?f=51&t=125)
As the linked forum topic suggests, for a workaround simply use the following:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
[[self view] setFrame:appFrame];
}
thank you for your answers. i did it somehow, playing with the tabbar's frame a bit.
[self.tabBarController.view setFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:tabBarController.view];
[self.view bringSubviewToFront:tabBarController.view];
i remember trying this a while ago and not working. now it did.
also, medling with bounds helped a bit.

How to present a modal view controller on the iphone without a "current" view controller?

I'm trying to open the email view controller (MFMailComposeViewController), and everything I read suggests using presentModalViewController:animated:, which seems to need to be sent to a UIViewController.
For example, in the documentation, it says:
Call the presentModalViewController:animated: method of the current view controller, passing in the view controller you want to present modally.
But I don't have a "current view controller"! My app is otherwise entirely OpenGL, and my setup code looks like:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.view = [[IPhoneView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window addSubview: self.view];
[window makeKeyAndVisible];
and I set up the OpenGL context in the IPhoneView class.
I've found a number of questions asking how to get a UIViewController from a UIView, and the consensus seems to be: don't. So how can I open the email view controller with that nifty sliding animation?
You can always do your own sliding animation of a view and just pass MFMailComposeViewController to it: Hidden Drawer example
See a similar sliding code here as well: How can I present a UIView from the bottom of the screen like a UIActionSheet?

View not completely covering the entire screen

Once again I've searched for about 45 minutes for an answer to this question and I thought I might have found the answer but then the situation I was reading wasn't exactly like the one I'm running into.
when I add my view it seems that it's not completely covering the window I was able to get rid of the status bar at the top but there is a section of space at the bottom that the view is not covering
alt text http://img177.imageshack.us/img177/8844/picture1zjv.png
as you can see from the screenshot there is an orange bar...it's orange because I know what it actually is under there (it's the viewController's view but everything I try I can't seem to get the added view to cover the screen.
this is the only code that's run
(void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:mainMenu];
}
Any help would be appreciated.
There are a few things that might be going wrong:
Your frame might be too short. In viewDidLoad: you can add a debug statement to check its height:
NSLog(#"Height is %f", self.view.frame.size.height);
It looks like you want that value to be 480, the full height of the screen.
Your origin might be too high. Similarly check your y offset:
NSLog(#"y origin is %f", self.view.frame.origin.y);
It looks like you want that value to be 0.
The origin of your superview might be too high. Assuming you this view only has one superview, this code will help check the absolute coordinates of your view's origin:
CGPoint absoluteOrigin = [self.view convertPoint:self.view.frame.origin
toView:self.view.superview];
NSLog(#"y origin in superview is %f", absoluteOrigin.y);
You can just tag on a few extra .superview's to find out the coordinates in terms of the prior views.
By the way, instead of just using 480 as a magic number in your code, you might want to do something like this to get the full height:
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat screenHeight = appFrame.size.height;
The applicationFrame property takes into account whether or not the status bar is displayed.
You should post your code, but in general, you can make a UIView fill the screen as follows:
UIView *foo = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
And you can set the frame later:
foo.frame = CGRectMake(0,0,320,480);
To fill the screen, you should use a 320 x 480 Rectangle, at origin (0,0). That's what that CGRectMake function above creates.
I've had this problem before, I fixed it by just moving the view down 20 pixels...
When you use interface builder it has that nifty little "simulate status bar" or "simulate toolbar" feature but I think its kind of finnicky.
Both Andrew and Tylers answers should work though, no shame in doing things programmatically :). If you are creating the stuff in interface builder, just do Andrew's second line though, don't need to reinitialize.
Ok, well I figured it out and now I feel kind of stupid...I went back to IB and realized that the height of each view was set at 460 and not 480...you guys did give me a bunch of good information and I appreciate it all. I wish I could mark them all as answers.
Thank you again,
BWC

iPhone how to create a full screen app?

I've been trying to create a full screen view. I plan on using core graphics for rendering. I am new to iPhone development so please forgive this basic question.
Here's my setup code;
- (void)loadView
{
CGRect rect = [[UIScreen mainScreen] bounds];
GameView *main_view;
main_view = [[GameView alloc] initWithFrame:rect ];
main_view.clearsContextBeforeDrawing = NO;
self.view = main_view;
[main_view release];
}
Yet when I run this I get a thin status bar at the top with the time and battery level.
I tried looking for some samples yet all the samples were opengles.
Could someone please tell me where I'm going wrong? And just how to create a full screen view.
Thanks
There are two methods;
In the info.plist for your application add a boolean key UIStatusBarHidden and set it to true.
At runtime you can call setStatusBarHidden on your application to show/hide the status bar. E.g.
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]
Since I just found the answer I was looking for here, I may as well add that the above method is now depreciated. The modern method is:
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation
Thanks!
You may also want to make your rect = [[UIScreen mainScreen] applicationFrame]
Add below method in respective view controller
-(BOOL) prefersStatusBarHidden
It worked for me.
This works and it is the easiest
UIViewControllerBasedStatusBarAppearance : NO in the .plist