iPhone app Custom UIWindow wrong frame in iPad Landscape orientation - ios

I am writing an iPhone app using custom UIWindow.(xCode6.1, iOS8.1)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
CGRect bounds = [[UIScreen mainScreen] bounds];
_window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, bounds.size.height, bounds.size.width)];
[_window setBackgroundColor:[UIColor greenColor]];
[_window makeKeyAndVisible];
return YES;
}
It targets iPhone, Landscape only. All works fine on all iPhone devices, but when it runs on iPad, the UIWindow frame is broken.
Any advice?

Related

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;
}

iPad App Landscape Mode broken iOS 8.3

I have an app for iPad and the app is only landscape right and left orientation..like printscreen:
and I'm using the following code to rotate the view to landscape mode:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI/2);
[self.window setTransform:rotate];
[self.window setFrame:CGRectMake(0, 0, 768, 1024)];
}
and the xib:
It worked fine..but now in iOS 8.3 it doesn't work. It appears wrong...see the image:
set auto layout constraints to your viewController objects.
and no need write this your code in didFinishLaunchingWithOptions
[[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI/2);
[self.window setTransform:rotate];
[self.window setFrame:CGRectMake(0, 0, 768, 1024)];

Issues Starting in Landscape with IIViewDeckController as RootController on iPad

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.

iOS UILaunchImageFile: some 4-inch-screen users see black borders

Some of my users seem to consistently see a clipped screen when running my app on their 4-inch devices. It may be limited to iPod Touch 5g users, and seems to occur on iOS6 and iOS7 (I am still investigating). I have what I think is a simple and correct UILaunchImageFile configuration, and it works fine on my iPhone 5 and in all the simulators. Any ideas?
Info.plist:
...
<key>UILaunchImageFile~ipad</key>
<string>UILaunchImage-iPad</string>
<key>UILaunchImageFile~iphone</key>
<string>UILaunchImage</string>
...
App product filesystem:
MyApp.app/
...
Info.plist
UILaunchImage-568h#2x.png (640x1136)
UILaunchImage-iPad.png (768x1024)
UILaunchImage-iPad#2x.png (1536x2048)
UILaunchImage.png (320x480)
UILaunchImage#2x.png (640x960)
...
[EDIT: my startup code, in MyAppDelegate]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
// screen.bounds is the whole display size;
// screen.applicationFrame is smaller when you show the status bar
UIScreen * screen = [UIScreen mainScreen];
CGRect screenBounds = screen.bounds;
CGRect applicationFrame = screen.applicationFrame;
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
// load main ui
MyUIViewController * main = [[[MyUIViewController alloc] initWithNibName:#"MyUIViewController" bundle:nil] autorelease];
UIView * rootView = [[[UIView alloc] initWithFrame:screenBounds] autorelease];
main.view = rootView;
[main loadIfNeeded];
self.viewController = main;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
...
}

Starts landscape orientation in iPad?

I have to tried iPad application for landscape orientation so do some changes in info.plist are
AppDelegate.m
- (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 whiteColor];
[self.window makeKeyAndVisible];
CGRect screenBound = [[UIScreen mainScreen] bounds];
NSLog(#"screenBound:%#",NSStringFromCGRect(screenBound));
return YES;
}
Then i get the screen resolution from CGRect is screenBound:{{0, 0}, {768, 1024}}
But i want {{0, 0}, {1024, 768}}, How to do this? please help me
Thanks in Advance
In your .plist instead UIInterfaceOrientation use UISupportedInterfaceOrientations, and make landscape orientaation the first one in UISupportedInterfaceOrientations list.
Place this line code in AppDelegate.m
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationLandscapeLeft;
}
May be help:
Write in this method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];

Resources