Issues Starting in Landscape with IIViewDeckController as RootController on iPad - ios

If I set a view deck controller as the AppDelegate window's root controller, when the app starts in landscape orientation on an iPad, the center view is displayed in it's Portrait orientation size and not resized to Landscape.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
IIViewDeckContoller *rootController = [IIViewDeckController new];
self.window.rootViewController = rootController;
self.window.backgroundColor = [UIColor blackColor];
[self.window makeKeyAndVisible];
}
However, if I create a simple controller as a root controller, and then present the view deck controller from this root controller, then everything seems to display just fine.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *simpleRootController = [UIViewController new];
IIViewDeckContoller *deckController = [IIViewDeckController new];
self.window.rootViewController = simpleRootController;
self.window.backgroundColor = [UIColor blackColor];
[self.window makeKeyAndVisible];
// View Deck Controller seems to have issues when it is the root controller of the main window.
// Presenting it as a modal seems to do the trick.
[simpleRootController presentViewController:self.deckController animated:NO completion:nil];
}
Anyone else run into this issue? Is there a better way to solve this? I do not see the same behavior with the iPhone.

I've seen some people having success with the following method in IIViewDeckController:
- (CGRect) referenceBounds {
if (self.referenceView) {
return self.referenceView.bounds;
}
CGRect bounds = [[UIScreen mainScreen] bounds]; // portrait bounds
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
bounds.size = CGSizeMake(bounds.size.height, bounds.size.width);
}
return bounds;
}
However, I'm not seeing anything change. I can't take the OP's advice of presenting the view controller due to some other restrictions.

Related

How to programmatically create UIView so that it does not overlap the status bar

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:

How to disable swipe gesture of UINavigation Controller

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

UIViewController trouble in landscape mode

I am trying create app without Story Book and xibs. It must work landscape mode only.
But I got trouble:
http://i.stack.imgur.com/FPzkk.png
Red - it's view of my controller. It's looks like it in wrong position and not rotated.
For create I use this code in AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
CGRect screenRect = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:screenRect];
EmulationViewController* cntr = [EmulationViewController sharedController];
[self.window addSubview:cntr.view];
[self.window makeKeyAndVisible];
return YES;
}
And
- (void)loadView
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
EmuWindow* view = [[EmuWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
view.backgroundColor =[UIColor redColor];
self.view = view;
}
It's tested on simulator with iOS 8. What I do wrong?
You need to make the view controller the root view controller, instead of this:
[self.window addSubview:cntr.view];
... do this:
self.window.rootViewController = cntr;
If you don't do this it won't get automatically rotated...
Then if you want it to always be in landscape, you can add this to the view controller code:
-(NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

Application windows are expected to have a root view controller at the end of application launch (Iphone App)

Im trying to make an Iphone app for my coursework and im getting the error
2015-06-26 00:41:31.721 My Movies[3313:6954045] Application windows are expected to have a root view controller at the end of application launch
Im currently running off Xcode 6.3.2 (6D2105)
This is what my AppDelegate.m finish launching options section looks like
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor blackColor];
// Create Film TableView and add it to Navigation Controller, then add Nav'Controller to Window
FilmTableTableViewController *vc = [[FilmTableTableViewController alloc] initWithStyle:UITableViewStylePlain];
navController = [[UINavigationController alloc] initWithRootViewController:vc];
[[self window] addSubview:[navController view]];
[self.window makeKeyAndVisible];
return YES;
Don't add the navcontroller as a subview.
Replace that with
// [[self window] addSubview:[navController view]];
[self.window setRootViewController:navController];

how do I set the orientation of a UIWindow with UINavigation

I'm adding the following code to my application in order to navigate back and forth from a quicklook view.
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self rotateView];
nav = [[UINavigationController alloc] initWithRootViewController:self];
[window addSubview:[nav view]];
[window makeKeyAndVisible];
[[self navigationController] setNavigationBarHidden:YES];
This code is run in my main ViewController viewDidLoad function. My application runs in landscape but this window and navigation bar loads in portrait mode. My application doesn't have a statusBar so some code I've found doesn't work. I get an error if I try to check and listen for status bar orientation notifications.
I'm looking for a way to allow this navigation view to set it's orientation based on the apps current orientation.
If I understand your question Your above code should be placed in didFinishLaunchingWithOptions not in viewDidLoad in the AppDelegate and the initialization of MainViewController should be there also.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.mainViewController = //init your MainViewController;
navigationController = [[UINavigationController alloc] initWithRootViewController:(UIViewController*)viewController];
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}

Resources