iPhone View Cutting Off - iphone

The view is created in interface builder, and is strangely cutting off at the bottom, and help or suggestions, is appreciated.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
Edit: I don't actually have a nib for the view controller, but instead a main window nib and a nib for two different views which are different themes.
Also if I use:
self.window.rootViewController = self.viewController;
it does not happen, but sadly this will crash in iOS 3.2 or below.

I experience the same problem, what I do is translating view 20 pixels down in ViewDidLoad then everything works fine. The problem surely is related to the statur bar but I do not know a solution other than this workaround.
To translate the view use this:
self.view.transform = CGAffineTransformMakeTranslation( 0, 20 );

In interface builder you need to check the dimensions of the view. You will see that it is too short (your height is probably set to 440, but it should be 460, or 480 if you don't have the status bar). This is probably why it appears to be cutting off.

Try enabling a simulated status bar in IB.

Related

Add a 'global' UIView to an App with StoryBoard

Is there a way to create a global UIView as background with the use of a StoryBoard?
I am updating my App, and making iOS 5 as the minimum so I can use ARC and also StoryBoards.
However, in my App I used a MainView.xib which I loaded as my rootviewcontroller, and any subsequent view was transparent so the background (and a button/copyright notice) were always visible.
I don't seem to be able to figure out how to do this. I can add the Subview to the rootview controller in the AppDelegate, but as soon as I seque to the next view it is gone.
Any suggestions how this can be done?
One way you can do this by adding an image view as a subview of the window itself, and making the backgrounds of all the view controllers clear.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIImageView *iv = [[UIImageView alloc] initWithFrame:self.window.frame];
iv.image = [UIImage imageNamed:#"BlueGreenGradient.tiff"];
[self.window addSubview:iv];
return YES;
}

When I Build and Run my iPhone Application on the simulator, Only a White screen Comes Up

I don't know what could be causing this. I chose "View Based Application". I just installed the newer (although not the newest) version of xCode, so to try it out, I made a tester application. I made a button that when clicked, alternates a label between shown and hidden. The program ran, no errors or warnings, but when the sim. brings it up, all there is is a blank screen with no button or label. I am truly clueless...
$- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
$
I don't know if there is something corrupt with this App Delegate method, but it seems as though that may be the problem (as this is the method loading and making the .xib file visible.
Thanks in advance!
You are missing this line:
self.window.rootViewController = self.viewController;
If it is still not working, I would recommend making a duplicate project and just copying and pasting the App Delegate code from that into your current project.
In the code where you create the button, do you add the button to the view? It would be done like this
[viewController.view addSubview:button];

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.

Why does an UIView in iOS/ appear too high up?

I'm relatively new to iOS programming. I have made a few basic apps before, and I'm getting back into it once again.
A problem I had a while back, and now is coming to haunt me is this.
When I create a new UIViewController subclass, myViewController (with xib) and add this code to get the add the view to the window, the contents always appear too high up, by the same width as the default/recommended left/right margin.
The code to add the view to the window is this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:[NSBundle mainBundle]];
[self setMyViewController:aViewController];
[aViewController release];
UIView *controllersView = [myViewController view];
[window addSubview:controllersView];
[window makeKeyAndVisible];
return YES;
}
For example, if I change the background colour of the view, I get a white strip at the bottom of the page when running in the simulator.
Any ideas?
Thanks
I don't think the problem is in that code. Although I guess you've done this already, it is probably a good idea to double check the .xib file. It may have an offset set in its position properties.
Also, it may be caused by the status bar not being set correctly. If you want to hide it, you can add an entry (UIStatusBarHidden -> true) in the info.plist file to set it to be hidden.
Either way check the dimensions of the .xib are the expected ones. And bear in mind the size of the status bar; the dimensions of the .xib file are different depending on whether the status bar is shown or not.

Two UITabBarControllers and Autorotation

I have two UITabBarControllers in my mainwnidow.nib wired to my appdelegate.
In my app delegate, I can load either one:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//either
[window addSubview:tabBarController.view];
//or
[window addSubview:tabBar2Controller.view];
[window makeKeyAndVisible];
}
and autorotation works.
If I add both (with the expectation to swap between them later):
[window addSubview:tabBarController.view];
[window addSubview:tabBar2Controller.view];
then autorotation stops working...everything is always portrait.
Thanks in advance for any tips...
Hmmm, I don't like this design. Typically windows should only have one subview.
Add another view controller that holds the instances of your tabBarControllers, and do the switching from there. That will fix your problem.
After thinking it through more, I realized I could just switch out the tabBarController.viewcontrollers array.
In IB I added both sets of tabs to a single tabbar, and then the appdelegate seperates them into two arrays and swaps between them as needed.
It works fine, but the jury is still out on whether the UI is effective