Interface Orientation Issue - iphone

I'm with a little problem. I have a TabBarController in my app, then one of the elements inside the tab bar is a navigation controller.
Well, inside my navigation controller, i want to play a video using web view.
My problem is: It's necessary to change the interface orientation of my web view. When i put a little bit of code, returning YES on the method shouldAutorotateToInterfaceOrientation (only for my web view's class), the video is still not changing the interface.
I've used a modal view controller to run my video, but we can see the same problem.
I don't have any idea about how to fix it, because i used all of my ios's knowledge.
Is there something to put inside my modal view controller to change my interface orientation?
My app has this kind of structure:
TabBarController->NavigationController ->VIew A->View B(Inside the View B, a ModalViewController)
Could someone help me?

If I understand correctly your question, you want to force the orientation of the device. This can be done by modifying the orientation of the status bar:
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];
For this to work, your app should be set so to support autorotation (returning YES from shouldAutorotateToInterfaceOrientation for all orientations); since you are using a navigation controller, also its root controller should return YES from shouldAutorotateToInterfaceOrientation.
You can call the above method when you need to switch orientation, i.e., at the moment you are going to play the video (when you load the web view, possibly).

Related

Rotate only one view controller in a tabbed application

I've read to many posts but I can't find a solution.
I've a tabbed application using storyboard. All the View Controllers of that Tabbed Application must show the content in portrait orientation, but there's only one viewcontroller (which is showing a video) that I want to be in landscape mode.
EXPLANATION OF THE STORYBOARD: TabBarController -> 4x Navigation controllers -> each navigation controller points to his ViewController -> one of these view controllers have an image, when I press that image, i've done a push to another view, the view that I want to have in landscape mode because I have there a UIWebView to show a video.
I'm unable to have all the app only in portrait orientation and the viewcontroller mentioned capable to rotate in landscape mode.
My app is also supporting iOS 5, so I know there are methods deprecated and I'm getting crazy.
I believe that in Summary > iPhone / iPod Deployment info > Supported Interface Orientations > there I've to check Portrait, Landscape left and right, and then via methods, enable or disable the rotations. I'm lost.
Can you help me?
I think you should be able to do this if you push to the view as a modal. Make sure your application's PList file (under Supporting Files folder) is set to support all orientations and then simply add the code to the modal view controller to display landscape with something like this.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOr‌​ientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
Let me know if you have any luck.
As i worked out for my App i advise you to use this solution.By using some conditions in the shouldAutorotateToInterfaceOrientation method orientation type we can solve this.Just try with this link will help you.
https://stackoverflow.com/questions/12021185/ios-rotate-view-only-one-view-controllers-view/15403129#1540312

Best practices for landscape only apps?

I'm a new iOS programming and I'm developing a simple iPhone game that needs to run in landscape only. I've ...
set supported orientations in the target settings
added the req. plist item (initial interface orientation)
overridden shouldAutorotateToInterfaceOrientation to return YES only for landscape modes
.. and the app "looks" correct, but there are a few odd things going on.
Issue 1 - I'm trying to manually position my views and not rely on autolayout. I've got a UIView in a NIB that I'm loading that needs to be positioned 150px from the right edge of the screen. I have to get the UIViewController's view's height (not width) to correctly position it - like it's not rotated to landscape at this point in the code.
Issue 2 - Implementing a UINavigationController to go from the title screen to the game interaction. When I'm pushing the interaction UIViewController to the stack, it slides in from the right like it's supposed to. When I go back to the title by popping the interaction, it slides UP to the title. It's seems like it's rotating back to portrait?
I think there is something very basic that I'm missing, but I can't find it in my app code. I've gone over the lists for a landscape app but they don't mention more than the list above.
Are there any other things/settings/methods to override that I should be on the look out for?
You need to set shouldAutorotateToInterfaceOrientation in your other viewControllers as well. Especially the ones displayed inside your UINavigationController.
Issue 2:
Don't use many UIViewController's. Use one view controller. Create one main UIViewController and for other UIViewController's just do:
[mainviewcontrl presentModalViewcontroller: child_viewcontrl animated: YES];
For delete a child view controller, use
[child_viewcontrl dismissModalViewControllerAnimated: YES];

UIsplitview Not Respond Rotation

I am developing app using UISplitview.
When I am Rotate the device form Landscap to Portrait I set the frame but It is not set.
In portrait mode only detailview is there. Landscap mode master and detail view is there.
So how can i Identify rotation in portrait mode ?
is it any kind of method is there?(like In view controller has willAnimationRotationtoInterfaceorientation)
from what I understand, you want to be able to see the master in the portrait view.
The design of UISplitViewController specifically hides master view in portrait mode.
There are two ways to go about the situation here. First of all, you declare your ViewController controller as the UISplitViewControllerDelegate. (which view controller as the delegate? the one that stays in the stack - for you to figure out whether it's master or detail).
Then you have a few delegate methods to take a look at.
If you want to straight up just show the master in portrait mode in the following delegate method:
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
you return NO (aka you don't want it to hide the view controller)
By default, this is no for landscape, which is why you see both views, and yes for portrait, which is why you don't see the master.
Saying that, the more elegant solution would probably be to hide the master view and then put a button at the top of the navigation bar, after clicking on which, you will be shown the master in portait mode. And upon clicking outside the master view, the master will be hidden.
To do this, you do not use the above BOOL method, but implement these other two delegate methods instead:
– splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
– splitViewController:willShowViewController:invalidatingBarButtonItem:
Search documentation for UISplitViewControllerDelegate.
Make a new project in Xcode using the Master-Detail Application Template for iPad. This project template creates a UISplitViewController that responds to interface orientation. Thus it shows you fully and precisely how to do what you're asking to do.

Prevent UIWebView in full screen to rotate

I have an UIWebView that might show a YouTube video, so when it happens it goes full screen. My app doesn't rotates, but the UIWebView rotates, so if i stop watching it in landscape mode, when i return to my screen it goes berserk.
How can i listen for when the user taps done or to directly avoid the UIWebView to rotate?
Thanks!
We regularly have portrait-only apps that show landscape videos via web views.
Are you sure you're returning NO for landscape orientations from your shouldAutorotateToOrientation: method of the top view controller? When you say "goes berserk," what do you mean? One thing I've found is that setting the main window's rootViewController property (rather than just adding your root view controller's view as a subview of the window view) can cause trouble when returning from videos like this.
I know I'm a few months late, but I've written a simple UINavigationController subclass to properly pass the shouldAutorotateToInterfaceOrientation, willRotateToInterfaceOrientation, and didRotateFromInterfaceOrientation calls through to the proper view controller.
Hope this helps :)
https://gist.github.com/bbae6291c4f6bf05d1eb
The method viewWillAppear: in your UIViewController will be called when the video is closed from full screen. You can adjust the view there by calling setNeedsDisplay on your UIView

How to force a screen orientation in specific view controllers?

My application is pretty simple: it starts up with a view controller that holds a table view (in grouped view layout) with a few options. When the user taps on one of the options, I push another view controller onto my navigation controller.
This second view controller simply displays a UIImageView, and the user can change the screen orientation on this view controller between portrait/landscape modes. This works just fine, and all is happy.
However, if the user taps on the "Back" button on my navigation bar while on the landscape mode, the first controller's layout is all messed up. See below for before/after screenshots:
(source: pessoal.org)
(source: pessoal.org)
Any clues on how to force the first view controller (second screenshot in this post) to stay within the portrait screen orientation?
There does not appear to be a way to do this using the documented methods.
I have filed a bug for this: rdar://6399924
"There is no way to always restrict a UIViewController to one orientation"
You can see it on open radar (along with a link to sample code to reproduce the problem) here: http://openradar.appspot.com/radar?id=697
Like someone on the open radar suggested, a workaround is to disable "back" button while in non-portrait:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
// don't let user press "back" button in landscape - otherwise previous view and the rest of the application
// will also be in landscape which we did not feel like testing yet
self.navigationController.navigationBarHidden = (UIInterfaceOrientationPortrait != self.interfaceOrientation);
}
There is a solution to do that : it's to use a view controller and adding its view to the window. then in that controller you force landscape in the shouldAutorotate... methode. It works fine, but be sure it's necessary for your project to use that, because it's not very smart  to force the user to turn his iPhone. By the way, here is an example code if you need it.
http://www.geckogeek.fr/iphone-forcer-le-mode-landscape-ou-portrait-en-cours-dexecution.html
I wasn't able to get this to work the way I wanted. You ought to be able to set a particular orientation for a ViewController, but the NavigationController doesn't seem to always do the right thing.
I ennded up re-designing my screens so that they all work in either orientation. That might be extra work, but it "feels" more natural, anyway.