How to set the starting orientation to landscape? - ios6

Hi I was checking the orientations changes of iOS6 and I made everything work fine except one thing. There is no way to start the app on landscape.
How can I do to start the app on landscape? I found this How to force a UIViewController to Portrait orientation in iOS 6 but that's not working, the app ALWAYS start in portrait and I needed to start it on landscape...
When I go to an other view and then go back to the "initial view" it is on landscape! But when the app starts it's on portrait...
Thank you!!
----------------------------- UPDATE -------------------------------
This is how I'm loading from the app delegate the main view:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
myViewController = [[myViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController:myViewController] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
----------------------------- UPDATE 2------------------------------
I made it work, I changed the previous code for:
self.navController = [[UINavigationController alloc] init] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
[navController presentViewController:myViewController animated:NO completion:NULL];
I hope this is useful for someone else!

Have you tried this?
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
or
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
This is working for me in both iOS 6 and iOS 5
I have another problem on trying to rotate the screen than I realize I was making the mistake of try to load the new screen with:
[self.navigationController presentModalViewController:controller animated:YES];
instead of:
[self.navigationController pushViewController:controller animated:YES];
the second one works but the first one wasn't doing what I expected.

This is how I made it work:
self.navController = [[UINavigationController alloc] init] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
[navController presentViewController:myViewController animated:NO completion:NULL];
I hope it helps someone else!

I've been wrestling with this too - this is how I've fixed it:
In viewDidLoad:
CGRect frame = self.view.bounds;
if (frame.size.height > frame.size.width) {
//hack to force landscape
CGFloat holdHeight = frame.size.height;
frame.size.height = frame.size.width;
frame.size.width = holdHeight;
self.view.bounds = frame;
}
But I'd prefer a better way.

Related

Can't dismiss AVPlayerViewController in iOS16

Since iOS 16 made changes to AVPlayerViewController, the dismiss button ('x') in the top left corner simply doesn't work. The 'tap' is normal, but it feels like the UIButton target doesn't do anything. I feel like I'm missing something obvious. Is there a delegate method or setting that needs to be used for it to work? It all worked perfectly before iOS 16. Implementation below:
AVPlayerViewController *vc = [[AVPlayerViewController alloc] init];
vc.player = [AVPlayer playerWithURL:[NSURL URLWithString:videoInfo.VideoURL]];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vc animated:NO completion:nil];
Using animation. It can be fixed but I don't know why.
[self presentViewController:vc animated:YES completion:nil];

iOS 11's Navigation Bar's RightBarButton greyed out when returning from a pushed ViewController

I set a LeftBarButton "Cancel" and a RightBarButton "OK" this way
_barButtonOK = [[UIBarButtonItem alloc] initWithTitle:#"OK" style:UIBarButtonItemStyleDone target:self action:#selector(barButtonOKAction)];
[_barButtonOK setTintColor:BUTTON_TEXTCOLOR];
[self.navigationItem setRightBarButtonItems:#[_barButtonOK]];
_barButtonCancel = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStyleDone target:self action:#selector(barButtonCancelAction)];
[_barButtonCancel setTintColor:BUTTON_TEXTCOLOR];
[self.navigationItem setLeftBarButtonItems:#[_barButtonCancel]];
and they look like this
But when I push a ViewController and then pop it back, the OK button looks like being disabled (actually it is still enabled) like this
It is fine with iOS 10 but just grays out with iOS 11 and I don't know why. Any advice will be appreciated.
The problem is gone after the upgrading of iOS/Xcode at some point of time. Definitely it was an iOS defect.

Rotation Not working in iOS-6.0 and above versions

I have prepared one view controller file named "CncWindowController" and In XIB file, i take window object (instead of UIView) and connected it to view outlet. So when I access its view, i get window object.
I'm accessing like it in AppDelegate.m file :
self.windowController = [[CncWindowController alloc] initWithNibName:#"CncWindowController" bundle:nil];
self.window = (UIWindow*) self.windowController.view;
Here, view is actually referring to window. But Rotation is not working in iOS6.0 and shouldAutorotate method is also not called.
If i will use window object like below then it works fine :
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
What is wrong with my approach ? Any help of ideas how i should work autorotation in iOS-6 too using above approach ?
Thanks!

Best implementation for transitionWithView in Navigation Controller when the user tap BACK

I have 2 UIViewControllers inside a NavigationController.
The first one, A, has just an UISearchBar on top of a tableView, as the tableHeader.
The second one, B, has a view in the upper part of the screen (let's call it a custom TableHeader) and a table below this view.
I wanted to simulate the modal transitionFlipFromRight when pushing from UIViewController A to UIViewControllerB and to simulate the modal transitionFlipFromLeft when popping from UIViewController B to UIViewController A when the user tap the navigationItem.backBarButtonItem.
No problem for the push side:
UIViewController *vcB = [UIViewController alloc] init];
[self.navigationController pushViewController: vcB animated: NO];
[UIView transitionWithView:self.navigationController.view
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromRight
animations:nil
completion:nil];
It works as expected.
I have problems implementing the pop, the switch back from UIViewController B to UIViewController A.
I added this code in the UIViewController B:
-(void) viewWillDisappear: (BOOL) animated
{
[super viewWilDisappear: NO]
[UIView transitionWithView:self.navigationController.view
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:nil];
}
I can see the flip but I am not satisfied with the result because for a fraction of a second after the switch from B to A I can still see the B custom tableHeader, moved from left border by 10 points.
Should I manage the transition from B to A in viewWillDisappear or I am totally wrong in doing this?
If I am wrong, What is the correct way to handle the pop animation?
Thanks
Nicola
Why dont you try this in your viewWillDisappear itself and check whether this works?
UIViewController *vcA = [UIViewController alloc] init];
[[self retain] autorelease];
[self.navigationController pushViewController: vcA animated: NO];
[UIView transitionWithView:self.navigationController.view
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:nil];
[self.navigationController popViewControllerAnimated:NO];
This is a tested code. So it works fine. This should help you.

completion:nil on presentModalViewController

When I set
[self presentModalViewController:Facebookcontroller animated:YES];
to
[self presentViewController:Facebookcontroller animated:YES completion:nil];
to erase the presentModalViewController:animated is deprecated: first deprecated in iOS 6.0
pops another warning:
Instance method '-presentModalViewController:animated:completion:' not found (return type defaults yo 'id')
Are you sure self is a UIViewController in this context. You can call this code only from another UIViewController.
Make sure you initialize the Facebookcontroller class first, you cannot pass just the class. Facebookcontroller *facebookController = Facebookcontroller alloc] init];
For iOS 6 use:
[self presentViewController:Facebookcontroller animated:YES completion:^{
//Do whatever you want to do when the controller 'Facebookcontroller' is presented.
}];
or
[self presentViewController:Facebookcontroller animated:YES completion:nil];
You can find the reference here.

Resources