title: Orientation of WebView - Monotouch
body: <p>I have a UIWebView that I can't seem to get to rotate. Everything in my app appears to work properly so far except for orientation (I want all orientations supported).</p>
  
  <p>In my code below, I'm using a WebViewDelegate in order to present users with a choice of which local application they would like to open the files downloaded from the website with vs. just handing it off to Safari).</p>
  
  <p>In my UIViewController this is set (properly from what I can tell)</p>
  
  <pre><code>public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
  {
      return true;        
  }
  </code></pre>
  
  <p>Here is my AppDelegate.</p>
  
  <pre><code>Register ("AppDelegate")] public partial class AppDelegate : UIApplicationDelegate { // class-level declarations UIWindow window; UIWebView webView;
  
  public override bool FinishedLaunching (UIApplication app, NSDictionary options)
  {
      // create a new window instance based on the screen size
      window = new UIWindow (UIScreen.MainScreen.ApplicationFrame);
  
  
      webView = new UIWebView (window.Bounds);
      window.AddSubview (webView); 
  
      string url = "https://www.myURL.com";
      webView.LoadRequest(new NSUrlRequest (new NSUrl (url)));
      webView.WeakDelegate = new WebViewDelegate();
      webView.ScalesPageToFit = true;
  
      var keys = new object[] { "UserAgent" };
      var objects = new object[] { "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3" };
      var dictionnary = NSDictionary.FromObjectsAndKeys(objects, keys);
  
      NSUserDefaults.StandardUserDefaults.RegisterDefaults(dictionnary);
  
      // make the window visible
      window.MakeKeyAndVisible ();
  
      return true;
  }
  
  
  
  }
  public class WebViewDelegate: UIWebViewDelegate{
  
  UIDocumentInteractionController docControl;
  
  public WebViewDelegate () : base()
  { 
  
  }
  
  
  public override bool ShouldStartLoad (UIWebView webView, MonoTouch.Foundation.NSUrlRequest request, UIWebViewNavigationType navigationType)
  {
  
      var docString = request.Url.ToString ();
      Uri uri = new Uri (docString);
      string ext = Path.GetExtension (uri.ToString ()).ToLower();
      var canShow = false;
  
      switch (ext) {
      case ".xls":
      case ".xlxs":
      case ".doc":
      case ".docx":
      case ".pdf":
      case ".jpeg":
      case ".jpg":
      case ".gif":
      case ".png":
      case ".mov":
      case ".mp4":
      case ".ogv":
      case ".webm":
      case ".avi":
      case ".mpeg":
      case ".mp3":
      case ".wmv":
          canShow = true;
          break;
      }
  
  
      if (canShow) {
  
          WebClient _webClient = new WebClient();
          _webClient.Headers.Add("SecretKey","SecretKey");
  
          string filename = Path.GetFileName(uri.ToString());
  
          string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
          string filePath = Path.Combine(path, filename);
  
          _webClient.DownloadFileAsync(uri,filePath);
          _webClient.DownloadFileCompleted +=  (sender, e) =&gt; {
  
  
              var docData = File.ReadAllBytes(filePath);
              File.WriteAllBytes(filePath, docData);
  
              InvokeOnMainThread(delegate {
                  docControl = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath));
                  docControl.Delegate = new UIDocumentInteractionControllerDelegate();
                  docControl.PresentOptionsMenu(new Rectangle(0,-260,320,320),webView,true);
              });
          };
  
          //open it in safari...
          //UIApplication.SharedApplication.OpenUrl(request.Url);
  
  
          return false;
      }
  
      return true;
  
      }
  
  }
  </code></pre>
  
  <p>And of course, in my Info.plist file I do have all (both portraits and both landscapes) supported for iPhone and iPad.</p>
  
  <p>Any help anyone can give would be greatly appreciated.</p>