iPad App Landscape Mode broken iOS 8.3 - ios

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

Related

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

self.window not working inside view controller

For iOS 7, I had status bar problem. For that I solved it by using below code in Appdelegate
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
self.window.bounds = CGRectMake(0,0, self.window.frame.size.width, self.window.frame.size.height);
}
All is working perfectly.
Only it gives problem while taking photo.
When I open camera or photo gallery, I still see status bar and because of that I see half of the navigation title as shown below.
Any idea how can I overcome this error?
The problems are :
Photo Gallery/ Camera comes like above image
If I click cancel, my view is shifted 20px up automatically.
Instead of:
self.window
Use this:
[[self view] window]
Try Like this:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
self.view.window.clipsToBounds =YES;
self.view.window.frame = CGRectMake(0,20,self.view.window.frame.size.width,self.view.window.frame.size.height-20);
self.view.window.bounds = CGRectMake(0,0, self.view.window.frame.size.width, self.view.window.frame.size.height);
}
I guess you are using the UINavigationController. There is nothing to do with the frame nor to do something with the Status Bar, If you are using UINavigationController. Please prefer the below code to set the UINavigationController along with Status bar set up. Else you can display the code, Will help you fix this.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ExViewController alloc] initWithNibName:#"ExViewController" bundle:nil];
self.window.rootViewController = self.viewController;
self.mainViewNavigation = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = mainViewNavigation;
[self.window addSubview:self.mainViewNavigation.view];
[self.window makeKeyAndVisible];
return YES;
}
I faced this problem wih one of my project. We didn't even have the xib for many classes. So all I could do is reset the frame once again in the delegate functions.
[self.navigationController dismissViewControllerAnimated:YES
completion:^{
[self.navigationController.view setFrame:CGRectMake(self.navigationController.view.frame.origin.x, [UIApplication sharedApplication].statusBarFrame.size.height, self.navigationController.view.frame.size.width, [[UIScreen mainScreen] bounds].size.height-[UIApplication sharedApplication].statusBarFrame.size.height)];
}];
I put this in the finish/cancel delegate methods of photo/camera picket, mail picker.

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

why the animation in the didFinishLaunchingWithOptions failed?

I just want to diaplay the view with animation in the didFinishLaunchingWithOptions, my codes are like the following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
CGRect finalRect = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
UIImage *image = [UIImage imageNamed:#"122.jpg"];
UIButton* pic = [[UIButton alloc] initWithFrame:finalRect];
[pic setBackgroundImage:image forState:UIControlStateNormal];
[pic setHidden:true];
pic.center = CGPointMake(finalRect.size.width / 2, finalRect.size.height / 2);
UIViewController* controller = [[UIViewController alloc] init];
[controller setView:pic];
[self.window setRootViewController:controller];
[self.window makeKeyAndVisible];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.5];
[pic setHidden:false];
[UIView commitAnimations];
return YES;
}
but the animation does not work at all. The subview with a picture just showed in the screen suddenly. But if I use a button to trigger the animation codes, the view will appear with animation as supposed to. Is there any restricts on the didFinishLaunchingWithOptions?
PS:
This problem is resolved by moving the animation codes into the viewDidAppear proc of the controller just like rokjarc said below.
But there is another solution for this by execute the animation codes in a delayed routine called from the didFinishLaunchingWithOptions like:
[self performSelector:#selector(executeAnimation) withObject:nil afterDelay:1];
Your button gets covered by controller.view which is also loaded in window.view on top of your pic.
You can solve this by moving the code to controller::viewDidAppear.
If you decide to go this way don't forget to add the button to controller.view instead of appDelegate.window.
Since it looks that you only want to show this animation at application launch you could set add a BOOL property called showAnimation to controller. Set this property to YES in didFinishLaunchingWithOptions: and to NO at the end of controller::viewDidAppear.
This way you can conditionally (if (self.showAnimation)...) show the desired animation only once (in controller::viewDidAppear).

Resources