Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Using timers</h2> <p>Auto scrolling can be implemented using an <code>NSTimer</code>. The challenge this solution bears is to figure out when to disable the timer to allow manual scrolling. I wasn't able to do the latter. Anyways, here is the code that enables autoscrolling using a timer:</p> <pre><code>self.WebViewAutoScrollTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0 target:self selector:@selector(scrollWebView:) userInfo:nil repeats:YES]; </code></pre> <p><code>scrollWebView:</code> simply being a method that calls <code>scrollToEndOfDocument:</code> on the web view.</p> <h2>Using notifications</h2> <p>Listing to <code>NSViewFrameDidChangeNotification</code> emitted by the web view allows to only scroll in the event of <em>frame size changes</em>. These changes occur when new content is added but also when the size of the encapsulating view changes, e.g. the window is resized. My implementation does not distinguish between those two scenarios.</p> <pre><code>NSClipView *contentView = self.webView.enclosingScrollView.contentView; [contentView setPostsFrameChangedNotifications:YES]; [[NSNotificationCenter defaultCenter] addObserverForName:NSViewFrameDidChangeNotification object:contentView queue:nil usingBlock:^(NSNotification *notification) { [self.webView scrollToEndOfDocument:self]; }]; </code></pre> <p><strong>Note:</strong> It is important that you instruct the content view of the web view's scroll view – <em>think about this a couple of times and it will start to make sense</em> – to post notifications when its frame size changes because <code>NSView</code> instances do not do this by default. This is accomplished using the first two lines of code in the example above.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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