Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was annoyed to find out that UIWebView is not a scroll view, so I made a custom subclass to get at the web view's scroll view. This suclass contains a scroll view so you can customize the behavior of your web view. The punchlines of this class are:</p> <pre><code>@class CustomWebView : UIWebview ... - (id) initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; // WebViews are subclass of NSObject and not UIScrollView and therefore don't allow customization. // However, a UIWebView is a UIScrollViewDelegate, so it must CONTAIN a ScrollView somewhere. // To use a web view like a scroll view, let's traverse the view hierarchy to find the scroll view inside the web view. for (UIView* v in self.subviews){ if ([v isKindOfClass:[UIScrollView class]]){ _scrollView = (UIScrollView*)v; break; } } return self; </code></pre> <p>}</p> <p>Then, when you create a custom web view, you can disable bouncing with:</p> <pre><code>customWebView.scrollView.bounces = NO; //(or customWebView.scrollView.alwaysBounceVertically = NO) </code></pre> <p>This is a great general purpose way to make a web view with customizable scrolling behavior. There are just a few things to watch out for:</p> <ul> <li>as with any view, you'll also need to override -(id)initWithCoder: if you use it in Interface Builder</li> <li>when you initially create a web view, its content size is always the same as the size of the view's frame. After you scroll the web, the content size represents the size of the actual web contents inside the view. To get around this, I did something hacky - calling -setContentOffset:CGPointMake(0,1)animated:YES to force an unnoticeable change that will set the proper content size of the web view.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload