Starts landscape orientation in iPad? - ios

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

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)];

iPhone app Custom UIWindow wrong frame in iPad Landscape orientation

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?

Status bar issue using xib

I have created two ViewCrontroller using xib and set orientation of UIViews is LandscapeLeft.
and than add this code to
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
The following is my ideal result:
I'd like the window under the status bar in ios 7,
The first view, the result is what I want to get, however, when it jumps to the second view, there is a problem! The window move 20px to the left. how to fit it into the normal view?
3.Most impornatant condition is Autolayout is "TRUE".
my testing code:
https://www.dropbox.com/s/bj9wg4hwar1t8y0/statusbartesting.zip
Can anyone help to solve this problem?
You don't need to change window frame in AppDelegate.
I'll tell you code, please follow it
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];
self.mxfirstciewcontroller = [[firstViewController alloc] initWithNibName:#"firstViewController" bundle:nil];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:self.mxfirstciewcontroller];
[(UINavigationController *)self.window.rootViewController setNavigationBarHidden:YES];
return YES;
}
In firstViewController.m
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.view setFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height)];
}
In secondViewController.m
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self.view setFrame:CGRectMake(20, 0, self.view.frame.size.width, self.view.frame.size.height)];
}

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.

Resources