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.
Related
i'm working on a uitabbar application and im wondering if its possible to put a view inside it.
my main purpose for this is i 2ill put a semi-transparent music player with about 20 pixels above the tabbar so when the user switches between other views the music play wont stop.
You can see a similar solution in Madonna App (whis is made with Mobile Roadie).
Thanks for helping again. hope someones knows this
You can put views "on top of" your entire application by putting them as subviews of the app's window. For example, this will "float" a red rectangle over your entire app (I tried it out in a tab-bar based app and it worked great):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the tab bar controller's view to the window and display.
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
UIView *myView = [[[UIView alloc] initWithFrame:CGRectMake( 50, 50, 50, 50 )] autorelease];
myView.backgroundColor = [UIColor redColor];
[self.window addSubview:myView];
return YES;
}
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 ...
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 was wondering how I would go about creating a view that persists through all the over views and controllers in the application. Similarly to how Soundcloud does it with their music player in their iPhone app (See pic). No matter where you go in the application the music player view stays at the top below the toolbar.
alt text http://i1.soundcloud.com/screenshots-000000000025-akaqgr-t500x500.jpg
The basic answer is to create a view at the top of the view hierarchy.
Let's take the example of your tab view-based screenshot above. Let's say the root view controller for the app is a subclass of UITabBarController called RootViewController.
Normally your application delegate will have a method that will look similar to this:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window addSubview:rootViewController.view];
[window makeKeyAndVisible];
}
If you want your view to just "overlap", that's simple. Let's say you want your "persistent view" to be 100 pixels tall and stretch the width of the screen. Assume you've already created a class for this view, and it's called PeristentView. Your code would look something like this:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window addSubview:rootViewController.view];
PersistentView* persistentView = [[PersistentView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
[window addSubview:persistentView];
[persistentView release];
[window makeKeyAndVisible];
}
The order here is important because you want the persistent view to be below in the view hierarchy, so that the rootViewController's view draws first, then the persistent view draws second.
If you want the persistent view to "push down" the the rest of the views on the screen, you'll have to change this up a bit. Given that by default you are telling the window to add the entirety of the root view controller's view as a subview, what you want to do instead is resize the frame of rootViewController.view so it doesn't take up the whole screen and reposition its origin.
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
PersistentView* persistentView = [[PersistentView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
[window addSubview:persistentView];
[persistentView release];
CGRect frame = rootViewController.view.frame;
frame.size.height -= persistentView.frame.size.height;
frame.origin.y += persistentView.frame.size.height;
rootViewController.view.frame = frame;
[window addSubview:rootViewController.view];
[window makeKeyAndVisible];
}
I just tested this with an existing tab bar-based project (using a plain UIView instead of creating a PersistentView class to bootstrap the test) and it works fine.
You can add a view as a subview of your main window, and position it above your tabBarController's view. It will then always be visible.