Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force UIView/UIVIewController orientation

We're writing an application that's in landscape mode exclusively. We use a transform on a root view to rotate it to LandscapeRight, then every view that gets loaded by that view shares the coordinate system. That's all fine and dandy, except one of our views has a UIWebView object that's being loaded by a view controller. The site that we're trying to look at doesn't have its content filling the view. When I view the same site in mobile Safari in landscape mode, it looks correct. My guess is that the View Controller we're using to host the WebView still thinks it's in portrait mode, as querying the interfaceOrientation of the property returns "1"...is there a way to trick a view/view controller to think it's in a specific orientation?

like image 209
Jonas Avatar asked Mar 13 '09 23:03

Jonas


People also ask

What is the difference between UIView and UIViewController?

They are separate classes: UIView is a class that represents the screen of the device of everything that is visible to the viewer, while UIViewController is a class that controls an instance of UIView, and handles all of the logic and code behind that view.

How do I change the orientation of Xcode?

You can configure which device orientation does your iOS app support in the Xcode target —> General —> Deployment Info section also. Just check the checkbox in the Deployment Info —> Device Orientation section.

How do I turn off landscape mode in iOS?

Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off.


1 Answers

Hopefully you've already found an answer for this, but you might try telling your app to just start out in landscape mode, rather than forcing it to always rotate to that orientation. Then if your root view's shouldAutorotateToInterfaceOrientation returns yes only for landscape modes, I'd bet you'd have the behavior you're looking for.

This guy seems to have a good tutorial about how to do all that. http://www.dejoware.com/blogpages/files/iphone_programming_landscape_view_tutorial.html

like image 160
Cruinh Avatar answered Sep 25 '22 06:09

Cruinh