Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not specific to the requirement here but helps in syncing scrollViews among different classes.</p> <p>To sync scrollViews between different classes, use NSNotificationCenter to observe for a particular notification. </p> <p>When scroll occurs then within the <strong>-scrollViewDidScroll:</strong> delegate method, use <strong>NSNotificationCenter</strong> to post the notification (with <strong>userInfo</strong> contents as <strong>scrollView.contentOffset.x</strong> &amp; <strong>scrollView.contentOffset.y</strong>) Example: </p> <pre><code>-(void)scrollViewDidScroll:(UIScrollView *)scrollView { NSMutableDictionary *userInfo = [[NSMutableDictionary alloc]init]; [userInfo setObject:[NSNumber numberWithFloat:scrollView.contentOffset.x] forKey:@"offsetX"]; [userInfo setObject:[NSNumber numberWithFloat:scrollView.contentOffset.y] forKey:@"offsetY"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"scrollSync" object:nil userInfo:userInfo]; } </code></pre> <hr> <p>Register for this notification in the same class or anyother class and perform the <strong>-setContentOffset:</strong> method on the scrollView/s you want synced.<br> .<br> <strong>Example on Adding Observer</strong> (either in didLoad or init or anywhere suitable to you in as many classes as you like):</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"scrollSync" object:nil]; </code></pre> <p>.<br> <strong>Example of the Selector Method</strong></p> <pre><code>-(void)handleNotification:(NSNotification *)sender { float newX = [[sender.userInfo objectForKey:@"offsetX"] floatValue]; float newY = [[sender.userInfo objectForKey:@"offsetY"] floatValue]; [myOtherScrollView setContentOffset:CGPointMake(newX,newY)]; } </code></pre>
    singulars
    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.
    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