0

I would simply like the WebView to be fullscreen without being able to scroll horizontal. I would like this for both portrait and landscape orientation.

I'm very new to iOS and I don't know how it works I feel like the storyboard and xib are very confusing compare to the xmls of android. When I open the src code it is quite a lot of code and I can't figure it out.

Shishi
  • 601
  • 2
  • 8
  • 27

2 Answers2

0

Let me illustrate an approach. Consider this untested pseudo-code.

@implementation MyViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
   CGSize contentSize = self.webView.scrollView.contentSize;

   switch (orientation) {
      case UIInterfaceOrientationPortrait:
        contentSize.width = 320.0;
        self.webView.scrollView.contentSize = contentSize;
        return YES;

      case UIInterfaceOrientationLandscapeLeft:
      case UIInterfaceOrientationLandscapeRight:
        contentSize.height = 568.0;
        self.webView.scrollView.contentSize = contentSize;
        return YES;
   }

   return NO;
}

@end

The idea here is that when the underlying scroll view's content size fits the screen dimensions scrolling should not be possible. This code reacts to orientation changes (when the device is turned) and adjusts the edge lengths to their respective screen dimensions.

One problem with this is that the device has to be turned at least once and after turning the phone in both directions, the contentSize is locked at {320, 568}. To get around this, consider this SO.

Community
  • 1
  • 1
glasz
  • 2,526
  • 25
  • 24
0

You can either in interface builder, tick the checkbox "Scales Page To Fit" for the Web View, this will ensure the UIWebView fits the contents to the iPhone/iPad's screen by shrinking it's size, which essentially disable the need for scrolling horizontally.

Or you can do the following: since UIWebView is contained within a UIScrollView, you can disable the scrolling for this UIScrollView by using the methods described in this SO link:How to disable horizontal scrolling of UIScrollView? You can access a WebView's scrollview by calling webview.scrollView

Community
  • 1
  • 1
Craig Zheng
  • 443
  • 1
  • 5
  • 17