Prevent UIWebView in full screen to rotate - iphone

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

Related

Interface Orientation Issue

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).

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

Change orientation of Subview of Application Window

i try to make an help view which should be able to be shown Modal on Top of all from everywhere in the App, so i thought onShow my help view gets the Application UIWindow and adds itself to it as an Subview. And onClose the help view removes itself as an subview from the Application UIWindow.
Everything works quite well, except if the user changes the orientation of the device. Is there any possibility to get the System to change the orientation of my UIView? I already tried to redraw my View on
- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
but unfortunately everything is rendered in the original orientation. It's like my is still in an different coordinate system.
Any suggestion would be great.
Thanks.
Why don't you just use presentModalViewController:animated: to present the controller? Everything should then work as expected.

presentModalViewController for UIImagePicker fails in landscape mode for iPhone 3.0

First of all, my code isn't complex - in fact it's just two sample programs from "Beginning iPhone Development: Exploring the iPhone SDK", combined into one program. I took the ViewSwitcher application, which switches between a blue view and a yellow view, and replaced the YellowViewController with the CameraViewController from the camera application.
I have three ViewControllers total. SwitchViewController just switches between BlueViewController and CameraViewController.
Inside CameraViewController, I'm trying to use a UIImagePickerController to choose an image. The picker is presented with presentModalViewController. The catch is that I want to do this in landscape orientation.
Everything works fine under 2.2.1, and everything works fine in 3.0 in portrait mode.
In 3.0 under landscape orientation, however, things break. If I set SwitchViewController to landscape orientation, my screen goes white when I try to present the picker. If I rotate the iPhone a few times, I can see a corner of the picker, which apparently was displayed off screen.
If I set CameraViewController to landscape orientation, the picker doesn't come up at all.
I think this page may have a clue when it says "The most prominent change [in 3.0] I can see is that the modal view controller will always use the application frame instead of the parent view controller's frame." I don't understand exactly what that means, though.
Any help is greatly appreciated. Thanks!
I believe what that means is this: Modal views always use the full screen, even if the parent view controller that invokes them controls a view that is only part of the screen. This makes sense for standard modal views like the camera picker, but I can see why someone who creates a custom modal view might want it to be smaller.
Not sure if that really helps solve your problem though.
Question -- what happens if you bring up the modal view and THEN rotate the phone?
You must have used addSubview in your parent view controller, try using presentModalViewController:.

Has anyone attempted and succeeded in getting Apple's iPhone PageControl demo to render correctly in Landscape mode?

I have had many successes programming the iPhone in Landscape mode, but I have been unable to get the Apple PageControl demo to run in Landscape mode and render the content correctly. The demo uses the AppDelegate class as an implicit ViewController which manages a UIScrollView, and the AppDelegate creates a set of UIViewControllers for the ScrollView's contents, 1 controller per page. In addition there is a UIPageControl object that the AppDelegate manages.
I can get the demo code to run in Landscape mode, but the contents always render as if they were in portrait mode, so while the simulator displays he device in Landscape mode, the pageControl is always on the side of the screen.
If anyone has gotten the contents to rotate correctly, I would really appreciate an explanation of how you got it to work.
I think it doesn't work because the scrollview is attached to window, and the window doesn't have a autorotate method like a view, it seems. If you put the scrollview in a view and then that view in the window, and the views controller has the shouldAutorotateToInterfaceOrientation method defined, it works. However, there is still a bit more work to do as the bounds of the pages are now wrong and need to be reset.