I am just looking at setting a up a custom UIViewController programatically (see code below) and I am just curious about the white line I am getting at the bottom of the display, I don't see this when I create the view using a NIB in InterfaceBuilder. Is it just a case of offsetting the frame down by the height of the status bar or am I missing something else?
EDIT:
Found it:
viewController.view.frame = CGRectMake(0.0,20.0,320.0,460.0);
CODE
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MyController *tempController = [[MyController alloc] init];
[self setMyController:tempController];
[window addSubview:[myController view]];
[window makeKeyAndVisible];
return YES;
}
SCREEN
Much appreciated ...
Gary
You could try setting up the frame of your controller's view to see what happens:
tempController.view.frame = CGRectMake(0, 0, 320, 480);
By the way, you have a probable memory leak in your method (that should be catched by clang if you enable it).
i guess this problem is related to bounds or Applicationframe. set everywhere bounds -'[[UIScreen mainScreen]bounds];' let's see ...
Related
I'm using addSubView twice in my app and both times it adds the view too high up the view, its off the screen at the top. See below... I have load the views like this as I nothing else works, cause me problems.
I just don't understand why they are showing off the screen?
What do I need to do to fix this ?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:rootController.view];
[window makeKeyAndVisible];
lvc = [[GettingStartedViewController alloc]
initWithNibName:#"GettingStartedView" bundle:nil];
[window addSubview:lvc.view];
return YES;
}
And in my GettingStartedView ...
- (IBAction) showHelp:(id)inSender {
theController = [[HelpViewController alloc] initWithNibName:#"HelpView"
bundle:nil onPage:HelpPageGettingStarted];
[self.view addSubview:theController.view];
}
Set the location:
rootController.view.frame = CGRectMake(0, 20, 320, 460);
Check the wantsFullScreenLayout property of your root view controller, make sure it's not set.
Hi i have a strange issue after adding my UIViewController.view to my Application Window.
I created a window based app and added my view in my appDelegates didFinishLaunchingWithOptions method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
overviewViewController *overView = [[overviewViewController alloc] initWithNibName:#"overviewViewController" bundle:nil];
//overView.view.bounds = CGRectMake(0.0f, 20.0f, 320.0f, 460.0f);
[window addSubview:overView.view];
//[overView release];
[window makeKeyAndVisible];
return YES;
}
clicking the "add" button presents a model view controller. after dismissing this modelViewController the main view fits perfectly.
as you can see, i also tried to set the bounds before adding my subview, without any success.
does anybody have some hints for me please, how to solve this problem?
You can fix this by setting this in your viewDidLoad method or even the viewWillAppear:
self.view.frame = [[UIScreen mainScreen] applicationFrame];
Also, I'm guessing you are hiding your status bar initially? Or do you have it always showing?
in your nib, check to make sure the simulated interface status bar is turned on so that it shows up when your editing your nib's view.
if this does not work, try setting the frame instead of bounds before you add it to the window.
I would like to clear a view before an application is switched away from, to change the launch image so that the next time the app is entered it will not display some insecure data.
iOS 4 provides applicationDidEnterBackground and applicationWillResignActive...however, neither of these seem to be able to prevent the screenshot from being taken before I have a chance to clear the view.
-applicationDidEnterBackground does get called before the screenshot. Turns out I was simply hiding my view improperly.
A simple way to clear the view was to set the hidden property on my UIView.
Just to add a snippet of code for a fast solution to this problem using a full background image declared on the initialization and hiding it.
You can do a more sofisticated hide of the particular contents of each view by registering to the notification, and in the views hide the particular views (labels) you want to hide.
Another solution is to check which viewcontroller is showing and switch between differente screenshots of the view of this viewcontroller without the data shown.
The easiest way:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIImageView *backgroundView_ = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default.png"]];
self.backgroundView = backgroundView_;
[backgroundView_ release];
// Add other controllers views
// ...
[self.window bringSubviewToFront:self.backgroundView];
self.backgroundView.hidden = YES;
[self.window makeKeyAndVisible];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
self.backgroundView.hidden = YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
self.backgroundView.hidden = NO;
}
I have the starter point of my application this window (white background):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
mainScreen = [[MainScreenController alloc] initWithNibName:#"MainScreenController" bundle:[NSBundle mainBundle]];
// add it to the main window
[window addSubview:[mainScreen view]];
// show view
[window makeKeyAndVisible];
NSLog(#"started");
return YES;
}
And MainScreenController is an UIViewController with (blackBackground) created by the Interface Builder.
The application executes perfectly but the first time, the black view is moved up like the height of the status iphone pannel (leaving white rectangle at the bottom).
If I rotate the iPhone twice, the view is perfectly positioned in the right place, filling all the screen with the black background.
Any idea?
Thanks!
Check your MainScreenController settings in IB. You should select a simulated status bar element (cmd-1) so that the view is positioned below the status bar initially.
EDIT - Why are you calling the initWithNibName in your delegate here? Most of the app templates I've used had the main view nib initialized by the OS and you use IB and set an IBOutlet in the main VC interface. You probably have an initial frame origin of {0,0} after calling initWithNibName. Add these lines after your initWithNibName call to verify this:
NSLog(#"mainscreen frame=%#", NSStringFromCGRect(mainscreen.view.frame));
CGRect frame = mainscreen.view.frame;
frame.origin.y = 20; // move below status bar
mainscreen.view.frame = frame;
I am just looking at setting up a simple viewController programatically, I have a ViewController.xib file that I have set the background color to RED in interface builder. I have also added the following to my AppDelegate.m
#implementation syntax_MapViewAppDelegate
#synthesize window;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
viewController = [[MapViewController alloc] init];
[window addSubview:[viewController view]];
[window makeKeyAndVisible];
return YES;
}
-(void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
#end
When I run the code it does what I expect apart from the white bar at the bottom of the screen, can anyone give me any pointers in how to remove this? I have a feeling I might need to position the view within the window, but I am not sure how?
cheers Gary
Please set your view frame.
viewController.view.frame = CGRectMake(0.0,20.0,320.0,460.0);
Now the view cover your full screen with Red color.
You can also set it from interface builder as well.
Something like this might save your problem:
[[viewController view] setFrame:CGRectMake(0, 20, 320, 460)];
Set your view to resize dynamically using the autoresizingMask or set it's frame explicitly.