I deleted story board and maininterface and from info plist now black screen appears with this code below
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIWindow * window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds] ];
UIViewController *UVC=[[UIViewController alloc] init];
UVC.view.bounds=[[UIScreen mainScreen]bounds] ;
UVC.title=#"AAA";
UVC.view.backgroundColor=[UIColor greenColor];
window.rootViewController = UVC;
[window makeKeyAndVisible];
application.delegate.window=window;
return YES;
}
its ios 13 issue.
Related
I am using the following code in my app delegate to programmatically create the application's window and root controller:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UIViewController alloc] init];
self.window.rootViewController.view = [[UIView alloc] init];
self.window.rootViewController.view.backgroundColor = [UIColor redColor];
return TRUE;
}
The code works fine, however the view associated to the root view controller overlaps the status bar, which I would like to avoid (see picture below).
How should I proceed? In particular I want to have a lightgray background for the status bar (similar to the apps created with a storyboard) and also handle orientation change correctly.
Thanks
Well, you can do something as following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UIViewController alloc] init];
self.window.rootViewController.view.backgroundColor = [UIColor whiteColor];
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0,
[UIApplication sharedApplication].statusBarFrame.size.height,
[UIScreen mainScreen].bounds.size.width,
[UIScreen mainScreen].bounds.size.height)];
redView.backgroundColor = [UIColor redColor];
[self.window.rootViewController.view addSubview:redView];
[self.window makeKeyAndVisible];
return TRUE;
}
should look like this:
In App Delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
WalkThrough *viewControllers=[[WalkThrough alloc]init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewControllers];
[self.window setRootViewController:self.navigationController];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
navigationController.navigationBar.hidden = YES;
self.window.backgroundColor = [UIColor clearColor];
[self.window makeKeyAndVisible];
return YES;
}
Try to disable interactivePopGestureRecognizer after [window makeKeyAndVisible].
The key to the problem is that interactivePopGestureRecognizer property is nil until both two conditions are met:
the navigationController is associated to the window
the window become key and visible
App content doesn't rotate if I use UINavigationController in my app. Only status bar orientation changes.
This is my didFinishLaunchingWithOptions method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
SpecificViewController *control=[sb instantiateViewControllerWithIdentifier:#"specific"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:control];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [self.window setRootViewController:navigationController];
return YES;
}
I dont understand why I am getting this result.
FOUND IT
Finally, I found a solution. But I don't understand why.
this is my didFinishLaunchingWithOptions method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window.rootViewController =nil;
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
SpecificViewController *control=[sb instantiateViewControllerWithIdentifier:#"specific"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:control];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
return YES;
}
And this is viewDidLoad method of SpecificViewController.
- (void)viewDidLoad {
[super viewDidLoad];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
self.navigationItem.title=#"The Title";
}
And I set "View controller-based status bar appearance" property to NO in plist file.
It is working now but I don't understand what do all these mean and why.
I don't think the answer you've accepted is the correct one here, I guess if it works for you that's great but it still looks wrong to me.
The reason rotation wasn't working was because you're using Storyboards which automatically create a UIWindow. Then in your application didFinishLaunching method you are alloc'ing a new UIWindow. Only the first UIWindow (created by your storyboard) will receive the rotation notifications, which is why you only noticed the status bar rotating and not your views.
The solution is to remove the following lines from your didFinishLaunchingWithOptions method:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
Your rootViewController will also be set in the storyboard, there's no need to set it again in code.
This works for me, try:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
SpecificViewController *control=[sb instantiateViewControllerWithIdentifier:#"specific"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:control];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
return YES;
}
add this to SpecificViewController.m
- (BOOL)prefersStatusBarHidden
{
return NO;
}
set "View controller-based status bar appearance" property to YES and remove "Main" from Main Interface options.You don't need to use setStatusBarHidden method.
In the (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method, I initialized an instance of UINavigationController with GeneralOptionsTableViewController and an instance of GeneralOptionsMapViewController. The navigationBar color was set to green. However, when I switch between the UINavigationController with GeneralOptionsTableViewController and GeneralOptionsMapViewController, the navigationBar becomes transparent. I tried resetting the navigationbar color in the viewWillAppear method but it does not seem to work.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
GeneralObjectTableViewController *generalObjectTableViewController = [[GeneralObjectTableViewController alloc] init];
GeneralObjectMapViewController *generalObjectMapViewController = [[GeneralObjectMapViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:generalObjectTableViewController];
navigationController.navigationBar.barTintColor = [UIColor greenColor];
UITabBarController *tabBarController = [[UITabBarController alloc]init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:navigationController, generalObjectMapViewController, nil]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
I am attempting to add an UIImageView as the first view that is shown after my Default.png disappears. This should be super easy but for some reason I am getting a black screen.
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIImageView *newimageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[newimageview setImage:[UIImage imageNamed:#"myimage.png"]];
[_window addSubview:newimageview];
[_window bringSubviewToFront:newimageview];
}
I also tried setting the background color of newimageview to see if I just wasn't loading my image file properly, but the screen still appeared black.
Any help would be appreciated, I feel pretty dumb at the moment.
I just created a new project and modified only the didFinishLaunchingWithOptions method. Here is exactly the code I am using. I changed nothing else in the project:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIImageView *newimageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bg-basketball"]];
[self.window addSubview:newimageview];
[self.window bringSubviewToFront:newimageview];
// Override point for customization after application launch.
//self.window.backgroundColor = [UIColor whiteColor];
//[self.window makeKeyAndVisible];
return YES;
}
And i am still getting the same black screen result.
I have added bg-basketball.png and bg-basketball#2x.png to my project and can see both images in XCode.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];//Add this line
This is works for me.